public static bool ExportToFBX(Component_Mesh sourceMesh, string realFileName, out string error) { //!!!!как для Vegetation. оверрайдить в Component_Mesh? //get mesh data var operations = new List <Component_RenderingPipeline.RenderSceneData.MeshDataRenderOperation>(); foreach (var geometry in sourceMesh.GetComponents <Component_MeshGeometry>()) { if (geometry.Enabled) { geometry.CompileDataOfThisObject(out var operation); if (operation != null) { operations.Add(operation); } } } //foreach( var geometry in mesh.Result.MeshData.RenderOperations ) //{ //} FbxManager manager = null; FbxIOSettings setting = null; FbxExporter exporter = null; FbxScene scene = null; try { //init FBX manager manager = FbxManager.Create(); setting = FbxIOSettings.Create(manager, "IOSRoot"); manager.SetIOSettings(setting); scene = FbxScene.Create(manager, "scene"); scene.GetGlobalSettings().SetAxisSystem(new FbxAxisSystem(FbxAxisSystem.EPreDefinedAxisSystem.eMax)); scene.GetGlobalSettings().SetSystemUnit(new FbxSystemUnit(100)); //init FBX scene for (int nOper = 0; nOper < operations.Count; nOper++) { var oper = operations[nOper]; //get data Vector3F[] positions = null; Vector3F[] normals = null; var texCoords = new List <Vector2F[]>(); ColorValue[] colors = null; Vector3F[] tangents = null; Vector3F[] binormals = null; //Position { if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Position, out VertexElement element) && element.Type == VertexElementType.Float3) { var buffer = oper.VertexBuffers[element.Source]; positions = buffer.ExtractChannel <Vector3F>(element.Offset); } } //Normal { if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Normal, out VertexElement element) && element.Type == VertexElementType.Float3) { var buffer = oper.VertexBuffers[element.Source]; normals = buffer.ExtractChannel <Vector3F>(element.Offset); } } //TexCoord for (var channel = VertexElementSemantic.TextureCoordinate0; channel <= VertexElementSemantic.TextureCoordinate3; channel++) { if (oper.VertexStructure.GetElementBySemantic(channel, out VertexElement element) && element.Type == VertexElementType.Float2) { var buffer = oper.VertexBuffers[element.Source]; texCoords.Add(buffer.ExtractChannel <Vector2F>(element.Offset)); } } //Color { if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Color0, out VertexElement element)) { if (element.Type == VertexElementType.Float4) { var buffer = oper.VertexBuffers[element.Source]; var values = buffer.ExtractChannel <Vector4F>(element.Offset); colors = new ColorValue[positions.Length]; int destIndex = 0; foreach (var p in values) { colors[destIndex++] = p.ToColorValue(); } } else if (element.Type == VertexElementType.ColorABGR) { //!!!!check var buffer = oper.VertexBuffers[element.Source]; var values = buffer.ExtractChannel <uint>(element.Offset); colors = new ColorValue[positions.Length]; int destIndex = 0; foreach (var p in values) { colors[destIndex++] = new ColorValue(ColorByte.FromABGR(p)); } } else if (element.Type == VertexElementType.ColorARGB) { //!!!!check var buffer = oper.VertexBuffers[element.Source]; var values = buffer.ExtractChannel <uint>(element.Offset); colors = new ColorValue[positions.Length]; int destIndex = 0; foreach (var p in values) { colors[destIndex++] = new ColorValue(ColorByte.FromARGB(p)); } } } } //Tangent, Binormal if (normals != null) { if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Tangent, out VertexElement element) && element.Type == VertexElementType.Float4) { var buffer = oper.VertexBuffers[element.Source]; var tangents4 = buffer.ExtractChannel <Vector4F>(element.Offset); tangents = new Vector3F[tangents4.Length]; binormals = new Vector3F[tangents4.Length]; int destIndex = 0; foreach (var p in tangents4) { tangents[destIndex] = p.ToVector3F(); binormals[destIndex] = Vector3F.Cross(p.ToVector3F(), normals[destIndex]) * p.W; destIndex++; } } } //indices int[] indices = null; if (oper.IndexBuffer != null) { indices = oper.IndexBuffer.Indices; } //create geometry var geometryName = "Geometry " + nOper.ToString(); var mesh = FbxMesh.Create(scene, geometryName); mesh.InitControlPoints(positions.Length); FbxLayerElementNormal elementNormals = null; if (normals != null) { elementNormals = mesh.CreateElementNormal(); elementNormals.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); elementNormals.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); } FbxLayerElementVertexColor elementColors = null; if (colors != null) { elementColors = mesh.CreateElementVertexColor(); elementColors.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); elementColors.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); } FbxLayerElementTangent elementTangents = null; if (tangents != null) { elementTangents = mesh.CreateElementTangent(); elementTangents.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); elementTangents.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); } FbxLayerElementBinormal elementBinormals = null; if (binormals != null) { elementBinormals = mesh.CreateElementBinormal(); elementBinormals.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); elementBinormals.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); } var uvElements = new List <FbxLayerElementUV>(); for (int uvIndex = 0; uvIndex < texCoords.Count; uvIndex++) { var pUVElement = mesh.CreateElementUV("texcoord" + uvIndex.ToString()); pUVElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); pUVElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); uvElements.Add(pUVElement); } for (int n = 0; n < positions.Length; n++) { mesh.SetControlPointAt(ToFbxVector4(positions[n]), n); if (normals != null) { elementNormals.GetDirectArray().Add(ToFbxVector4(normals[n])); } for (int uvIndex = 0; uvIndex < texCoords.Count; uvIndex++) { var texCoord = texCoords[uvIndex][n]; texCoord.Y = 1.0f - texCoord.Y; uvElements[uvIndex].GetDirectArray().Add(ToFbxVector2(texCoord)); } if (colors != null) { elementColors.GetDirectArray().Add(ToFbxColor(colors[n])); } if (tangents != null) { elementTangents.GetDirectArray().Add(ToFbxVector4(tangents[n])); } if (binormals != null) { elementBinormals.GetDirectArray().Add(ToFbxVector4(binormals[n])); } } if (normals != null) { mesh.GetLayer(0).SetNormals(elementNormals); } if (colors != null) { mesh.GetLayer(0).SetVertexColors(elementColors); } if (tangents != null) { mesh.GetLayer(0).SetTangents(elementTangents); } if (binormals != null) { mesh.GetLayer(0).SetBinormals(elementBinormals); } int polygonCount = indices.Length / 3; for (int i = 0; i < polygonCount; i++) { mesh.BeginPolygon(-1, -1, -1, false); for (int j = 0; j < 3; j++) { int currentIndex = i * 3 + j; int vertexIndex = indices[currentIndex]; mesh.AddPolygon(vertexIndex); } mesh.EndPolygon(); } var node = FbxNode.Create(scene, geometryName); node.SetNodeAttribute(mesh); scene.GetRootNode().AddChild(mesh.GetNode()); } //save exporter = FbxExporter.Create(manager, ""); if (!exporter.Initialize(realFileName, -1, manager.GetIOSettings())) { error = "Can't initialize FBX exporter."; return(false); } if (!exporter.Export(scene)) { error = "Export to FBX failed."; return(false); } } finally { try { scene?.Destroy(); } catch { } try { exporter?.Destroy(); } catch { } try { setting?.Destroy(); } catch { } try { manager?.Destroy(); } catch { } } foreach (var op in operations) { op.DisposeBuffers(); } error = ""; return(true); }
public new static FbxSubDiv Create(FbxManager pManager, string pName) { global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxSubDiv_Create__SWIG_0(FbxManager.getCPtr(pManager), pName); FbxSubDiv ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSubDiv(cPtr, false); return(ret); }
// override void Dispose() {base.Dispose();} public new static FbxSurfaceLambert Create(FbxManager pManager, string pName) { global::System.IntPtr cPtr = NativeMethods.FbxSurfaceLambert_Create__SWIG_0(FbxManager.getCPtr(pManager), pName); FbxSurfaceLambert ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxSurfaceLambert(cPtr, false); if (NativeMethods.SWIGPendingException.Pending) { throw NativeMethods.SWIGPendingException.Retrieve(); } return(ret); }
public new static FbxDocument Create(FbxManager pManager, string pName) { global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxDocument_Create__SWIG_0(FbxManager.getCPtr(pManager), pName); FbxDocument ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxDocument(cPtr, false); return(ret); }
public FbxObject Create(FbxManager pManager, string pName, FbxObject pFrom) { global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxClassId_Create(swigCPtr, FbxManager.getCPtr(pManager), pName, FbxObject.getCPtr(pFrom)); FbxObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxObject(cPtr, false); if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static void ExportMesh(Mesh mesh, string directory, string fileName) { var filePath = Path.Combine(directory, fileName); // Make a temporary copy of the mesh to modify it Mesh tempMesh = Object.Instantiate(mesh); tempMesh.name = mesh.name; // If meters, divide by 100 since default is cm. Assume centered at origin. if (fbxUnit == FbxSystemUnit.m) { Vector3[] vertices = tempMesh.vertices; for (int i = 0; i < vertices.Length; ++i) { vertices[i] /= 100.0f; } tempMesh.vertices = vertices; } // You could handle other SystemUnits here // FBX Manager FbxManager manager = FbxManager.Create(); manager.SetIOSettings(FbxIOSettings.Create(manager, Globals.IOSROOT)); // FBX Exporter FbxExporter fbxExporter = FbxExporter.Create(manager, "Exporter"); // Binary int fileFormat = -1; // Ascii if (saveFbxAsAscii) { fileFormat = manager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)"); } fbxExporter.Initialize(filePath, fileFormat, manager.GetIOSettings()); fbxExporter.SetFileExportVersion("FBX201400"); // FBX Scene FbxScene fbxScene = FbxScene.Create(manager, "Scene"); FbxDocumentInfo sceneInfo = FbxDocumentInfo.Create(manager, "SceneInfo"); // Set up scene info sceneInfo.mTitle = fbxFileTitle; sceneInfo.mSubject = fbxFileSubject; sceneInfo.mComment = fbxFileComment; sceneInfo.mAuthor = fbxFileAuthor; sceneInfo.mRevision = fbxFileRevision; sceneInfo.mKeywords = fbxFileKeywords; sceneInfo.Original_ApplicationName.Set(fbxFileApplication); sceneInfo.LastSaved_ApplicationName.Set(fbxFileApplication); fbxScene.SetSceneInfo(sceneInfo); // Set up Global settings FbxGlobalSettings globalSettings = fbxScene.GetGlobalSettings(); globalSettings.SetSystemUnit(fbxUnit); globalSettings.SetAxisSystem(fbxAxisSystem); FbxNode modelNode = FbxNode.Create(fbxScene, tempMesh.name); // Add mesh to a node in the scene // TODO Wat??? // using (ModelExporter modelExporter = new ModelExporter()) // { // if (!modelExporter.ExportMesh(tempMesh, modelNode)) // Debug.LogError("Problem Exporting Mesh"); // } // add the model to the scene fbxScene.GetRootNode().AddChild(modelNode); // Finally actually save the scene bool sceneSuccess = fbxExporter.Export(fbxScene); AssetDatabase.Refresh(); // clean up temporary model if (Application.isPlaying) { Object.Destroy(tempMesh); } else { Object.DestroyImmediate(tempMesh); } }
/* Create an object with another manager. Default implementation uses * reflection to call T.Create(...); override if reflection is wrong. */ public virtual T CreateObject(FbxManager mgr, string name = "") { return(Invoker.InvokeStatic <T>(s_createFromMgrAndName, mgr, name)); }
public new static FbxProcessorShaderDependency Create(FbxManager pManager, string pName) { global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxProcessorShaderDependency_Create__SWIG_0(FbxManager.getCPtr(pManager), pName); FbxProcessorShaderDependency ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxProcessorShaderDependency(cPtr, false); return(ret); }
public FbxMaterialConverter(FbxManager mManager, FbxSurfaceMaterial pDefaultMaterial) : this(FbxWrapperNativePINVOKE.new_FbxMaterialConverter__SWIG_0(FbxManager.getCPtr(mManager), FbxSurfaceMaterial.getCPtr(pDefaultMaterial)), true) { if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } }
protected override FbxScene CreateScene(FbxManager manager) { FbxScene scene = base.CreateScene(manager); FbxNode cameraNode = scene.GetRootNode().GetChild(0); FbxCamera camera = FbxCamera.Create(scene, "camera"); camera.ProjectionType.Set(FbxCamera.EProjectionType.ePerspective); camera.SetAspect(FbxCamera.EAspectRatioMode.eFixedRatio, 300, 400); camera.FilmAspectRatio.Set(240); camera.SetApertureWidth(4); camera.SetApertureHeight(2); camera.SetApertureMode(FbxCamera.EApertureMode.eFocalLength); camera.FocalLength.Set(32); camera.SetNearPlane(1); camera.SetFarPlane(100); // create custom property (background color) var bgColorProperty = FbxProperty.Create(cameraNode, Globals.FbxColor4DT, "backgroundColor"); Assert.IsTrue(bgColorProperty.IsValid()); bgColorProperty.Set(new FbxColor(0.5, 0.4, 0.1, 1)); // Must be marked user-defined or it won't be shown in most DCCs bgColorProperty.ModifyFlag(FbxPropertyFlags.EFlags.eUserDefined, true); bgColorProperty.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true); Assert.IsTrue(bgColorProperty.GetFlag(FbxPropertyFlags.EFlags.eUserDefined)); Assert.IsTrue(bgColorProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable)); // create custom property (clear flags) var clearFlagsProperty = FbxProperty.Create(cameraNode, Globals.FbxIntDT, "clearFlags"); Assert.IsTrue(clearFlagsProperty.IsValid()); clearFlagsProperty.Set(4); // Must be marked user-defined or it won't be shown in most DCCs clearFlagsProperty.ModifyFlag(FbxPropertyFlags.EFlags.eUserDefined, true); clearFlagsProperty.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true); Assert.IsTrue(clearFlagsProperty.GetFlag(FbxPropertyFlags.EFlags.eUserDefined)); Assert.IsTrue(clearFlagsProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable)); // Add camera properties to animation clip FbxAnimStack animStack = scene.GetCurrentAnimationStack(); FbxAnimLayer animLayer = animStack.GetAnimLayerMember(); // TODO: (UNI-19438) Figure out why trying to do GetCurve for NearPlane always returns null CreateAnimCurves(cameraNode, animLayer, new List <PropertyComponentPair> () { new PropertyComponentPair("backgroundColor", new string[] { Globals.FBXSDK_CURVENODE_COLOR_RED, Globals.FBXSDK_CURVENODE_COLOR_GREEN, Globals.FBXSDK_CURVENODE_COLOR_BLUE, "W" }), new PropertyComponentPair("FocalLength", new string[] { null }), new PropertyComponentPair("clearFlags", new string[] { null }) }, (index) => { return(index); }, (index) => { return(index / 5.0f); }, camera); cameraNode.SetNodeAttribute(camera); // set the default camera scene.GetGlobalSettings().SetDefaultCamera(cameraNode.GetName()); return(scene); }
public new static FbxAnimCurveBase Create(FbxManager pManager, string pName) { global::System.IntPtr cPtr = FbxWrapperNativePINVOKE.FbxAnimCurveBase_Create(FbxManager.getCPtr(pManager), pName); FbxAnimCurveBase ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxAnimCurveBase(cPtr, false); return(ret); }
protected override FbxScene CreateScene(FbxManager manager) { FbxScene scene = FbxScene.Create(manager, "myScene"); // Create the following node hierarchy with transforms: // Root // (t: 0,10,4) // (r: 0,0,0) // (s: 1,1,1) // / \ // child0 child1 // (t: 1,1,1) (t: 0,0,0) // (r: 0,0,90) (r: 180,5,0) // (s: 2,2,2) (s: 3,2,1) // | // child2 // (t: 5,6,20) // (r: 0,10,0) // (s: 1,0.5,1) FbxNode root = FbxNode.Create(scene, "Root"); root.SetNodeAttribute(ExportNull(scene)); root.SetShadingMode(FbxNode.EShadingMode.eWireFrame); // Set the transform values root.LclTranslation.Set(new FbxDouble3(0, 10, 4)); root.LclRotation.Set(new FbxDouble3(0, 0, 0)); root.LclScaling.Set(new FbxDouble3(1, 1, 1)); // Set the pre/post rotation, pivots and offsets // NOTE: For some reason when using PreRotation.Set() instead of SetPreRotation(), // the PreRotation does not get imported properly. Same is true for the other properties. // Also only works if EPivot set is SourcePivot. // TODO: figure out why the other ways don't work. root.SetPreRotation(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(30, 10, 45)); root.SetPostRotation(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(9, 10, 5)); root.SetRotationPivot(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(5, 6, 7)); root.SetScalingPivot(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(1, 2, 1)); root.SetRotationOffset(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(0.6, 8, 0.3)); root.SetScalingOffset(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(10, 4, 3)); FbxNode[] children = new FbxNode[3]; FbxDouble3[][] transforms = { new FbxDouble3[] { new FbxDouble3(1, 1, 1), new FbxDouble3(0, 0, 90), new FbxDouble3(2, 2, 2) }, new FbxDouble3[] { new FbxDouble3(0, 0, 0), new FbxDouble3(180, 5, 0), new FbxDouble3(3, 2, 1) }, new FbxDouble3[] { new FbxDouble3(5, 6, 20), new FbxDouble3(0, 10, 0), new FbxDouble3(1, 0.5, 1) } }; for (int i = 0; i < children.Length; i++) { children [i] = FbxNode.Create(scene, "Child" + i); // set the fbxNode's node attribute children[i].SetNodeAttribute(ExportNull(scene)); children[i].SetShadingMode(FbxNode.EShadingMode.eWireFrame); // set the transform children [i].LclTranslation.Set(transforms [i] [0]); children [i].LclRotation.Set(transforms [i] [1]); children [i].LclScaling.Set(transforms [i] [2]); // set some values to check against later (doesn't really matter what the values are) children [i].SetPreRotation(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(i, i * 2, i % 3)); children [i].SetPostRotation(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(i - 1, i + 5, i)); children [i].SetRotationPivot(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(i / 2, i, i + 3)); children [i].SetScalingPivot(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(i * 5, i - 1, i / 4)); children [i].SetRotationOffset(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(0.6 * i, 8, i / 2.0f)); children [i].SetScalingOffset(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(i, i, i)); } // Create the hierarchy scene.GetRootNode().AddChild(root); root.AddChild(children [0]); root.AddChild(children [1]); children [1].AddChild(children [2]); return(scene); }
void PrintAttribute(FbxManager manager, FbxNodeAttribute attri) { FbxLayerElementVertexColor pp; Log.Info("attri " + attri.GetName()); Log.Info("attri type " + Enum.GetName(typeof(FbxNodeAttribute.EType), attri.GetAttributeType())); //attri.is if (attri.GetAttributeType() == FbxNodeAttribute.EType.eMesh) { Type t = attri.GetType(); Log.Info("type name " + t.Name); FbxMesh mesh = attri.GetNode().GetMesh(); //FbxMesh mesh = attri as FbxMesh; if (mesh == null) { Log.Error("convert mesh failed!"); return; } Console.WriteLine($"mesh.GetMeshEdgeCount() = {mesh.GetMeshEdgeCount()}; mesh.GetPolygonCount() = {mesh.GetPolygonCount()}; mesh.GetPolygonVertexCount()={mesh.GetPolygonVertexCount()}; " + $"mesh.GetTextureUVCount() {mesh.GetTextureUVCount()}; mesh.GetControlPointsCount()={mesh.GetControlPointsCount()}; mesh.GetElementTangentCount()={mesh.GetElementTangentCount()};" + $" mesh.GetElementNormalCount()={mesh.GetElementNormalCount()}; mesh.GetElementVertexColorCount()={mesh.GetElementVertexColorCount()};" + $"mesh.GetUVLayerCount() = {mesh.GetUVLayerCount()}; mesh.GetLayerCount() = {mesh.GetLayerCount()}"); var pts = mesh.GetControlPoints(); var ar = FbxVector4Array.frompointer(pts); for (int i = 0; i < mesh.GetLayerCount(); i++) { var layer = mesh.GetLayer(i); } try { var v2 = new FbxVector2(); IntPtr mem = Marshal.AllocHGlobal(4); FbxStringList lst = new FbxStringList(); //int nameCount = lst.GetCount(); mesh.GetUVSetNames(lst); //ToDo : что за List, расширяется ли он сам? var name = lst.GetItemAt(0).mString.Buffer(); //var myBool = new _MyBool(mem); //var res = mesh.GetPolygonVertexUV(0, 0, name, v2, myBool); // var c0 = v2.at(0); // var c2 = v2.at(1); var fbxArV2 = new FbxArrayFbxVector2(); var fbxArI = new FbxArrayInt(); var res = mesh.GetPolygonVertexUVs(name, fbxArV2, fbxArI); var ptr = fbxArV2.GetAt(2).mData; double coord1 = FbxWrapperNative.DoubleArrayFunc_getitem(ptr, 0); double coord2 = FbxWrapperNative.DoubleArrayFunc_getitem(ptr, 1); var param = FbxWrapperNative.new_FbxLayerElementArrayTemplateIntPtrFunc(); res = mesh.GetMaterialIndices(param); var param2 = FbxWrapperNative.FbxLayerElementArrayTemplateIntPtrFunc_value(param); int count = param2.GetCount(); List <int> mind = new List <int>(); for (int i = 0; i < count; i++) { mind.Add(param2.GetAt(i)); } //var vec = new FbxVector4Array(5); //var res2 = mesh.GetPolygonVertexUVs("", , null); bool res1 = mesh.GenerateTangentsData(0); //bool res2 = mesh.GenerateTangentsDataForAllUVSets( ); var tCount = mesh.GetElementTangentCount(); var tang = mesh.GetElementTangent( ); var tangAr = tang.GetDirectArray(); int tC = tangAr.GetCount(); //int binCount = mesh.GetElementBinormalCount(); //var bin = mesh.GetElementBinormal().GetDirectArray().GetCount(); } catch (Exception ex) { } //var vertices = mesh.GetPolygonVertices(); //FbxMesh mesh; //FbxLayerElementUV uv = mesh.GetElementUV(); //uv.GetDirectArray() FbxLayerElementNormal normal = mesh.GetElementNormal(); //ToDo //DirectArrayFbxVector4 array = normal.GetDirectArray(); var array = normal.GetDirectArray(); Log.Info("normal count " + array.GetCount()); //for (int i = 0; i < array.GetCount(); i++) //{ // FbxVector4 v = array.GetAt(i); // SWIGTYPE_p_double data = v.mData; // DoubleArray d = DoubleArray.frompointer(data); // PrintDoubleArray(d, 4); //} } }
void Run() { FbxManager manager = FbxManager.Create(); FbxIOSettings setting = FbxIOSettings.Create(manager, "IOSRoot"); //fbxiosettingspath.h //PostProcessSteps.CalculateTangentSpace = #define EXP_TANGENTSPACE EXP_GEOMETRY "|" IOSN_TANGENTS_BINORMALS //PostProcessSteps.JoinIdenticalVertices = #define IOSN_DXF_WELD_VERTICES "WeldVertices" //PostProcessSteps.Triangulate = #define IOSN_TRIANGULATE "Triangulate" //PostProcessSteps.RemoveComponent = //PostProcessSteps.GenerateSmoothNormals = //setting.AddProperty() setting.SetBoolProp("Import|AdvOptGrp|Dxf|WeldVertices", true); setting.SetBoolProp("Triangulate", true); manager.SetIOSettings(setting); FbxImporter impoter = FbxImporter.Create(manager, ""); bool status = impoter.Initialize(@"1.fbx", -1, setting); Log.Info(status); if (!status) { return; } FbxScene scene = FbxScene.Create(manager, "scene1"); status = impoter.Import(scene); Log.Info(status); int numTrack = scene.GetSrcObjectCount(FbxCriteria.ObjectType(FbxAnimStack.ClassId)); Log.Info("num stack " + numTrack); FbxObject obj = scene.GetSrcObject(FbxCriteria.ObjectType(FbxAnimStack.ClassId), 0); FbxAnimStack stack = FbxAnimStack.Cast(obj); if (stack == null) { Log.Error("can not get anim stack!"); return; } FbxCriteria cri = FbxCriteria.ObjectTypeStrict(FbxAnimLayer.ClassId); int numLayer = stack.GetMemberCount(cri); Log.Info("anim layer count : " + numLayer); FbxAnimLayer layer = null; if (numLayer > 0) { FbxObject layerobj = stack.GetMember(cri, 0); layer = FbxAnimLayer.Cast(layerobj); if (layer == null) { Log.Error("anim layer is null!"); return; } Log.Info("anim layer name " + layer.GetName()); } Log.Info("node count " + scene.GetNodeCount()); for (int i = 0; i < scene.GetNodeCount(); i++) { FbxNode node = scene.GetNode(i); Log.Info("node " + i + " " + node.GetName() + " ChildCount:" + node.GetChildCount()); //---------------- //node.LclTranslation.IsAnimated //---------------- //ToDo : if (node.LclTranslation.IsAnimated(layer)) { FbxAnimCurveNode curveNode = node.LclTranslation.GetCurveNode(layer); if (curveNode == null) { Log.Error("curve node is null"); } else { for (int c = 0; c < curveNode.GetCurveCount(0); c++) { FbxAnimCurve curve = curveNode.GetCurve(0, (uint)c); if (curve != null) { Log.Info("curve " + curve.GetName()); Log.Info("key count " + curve.KeyGetCount()); FbxAnimCurveKey key = curve.KeyGet(0); FbxTime t = key.GetTime(); Log.Info("key " + t.GetTimeString() + " value " + key.GetValue()); } } } } if (node.GetNodeAttribute() != null) { Log.Info("got attribu"); FbxNodeAttribute att = node.GetNodeAttribute(); PrintAttribute(manager, att); } else { Log.Info("att count " + node.GetNodeAttributeCount()); for (int j = 0; j < node.GetNodeAttributeCount(); j++) { FbxNodeAttribute att = node.GetNodeAttributeByIndex(j); PrintAttribute(manager, att); } } FbxVector4 rot = node.GetPostRotation(FbxNode.EPivotSet.eSourcePivot); FbxQuaternion q; } }
public void Init() { m_fbxManager = FbxManager.Create(); }
public FbxMaterialConverter(FbxManager mManager) : this(FbxWrapperNativePINVOKE.new_FbxMaterialConverter__SWIG_1(FbxManager.getCPtr(mManager)), true) { if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } }
/// <summary> /// Import all from scene. /// Return the number of objects we imported. /// </summary> public int ImportAll() { // Create the FBX manager using (var fbxManager = FbxManager.Create()) { FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT); // Configure the IO settings. fbxManager.SetIOSettings(fbxIOSettings); // Get the version number of the FBX files generated by the // version of FBX SDK that you are using. int sdkMajor = -1, sdkMinor = -1, sdkRevision = -1; FbxManager.GetFileFormatVersion(out sdkMajor, out sdkMinor, out sdkRevision); // Create the importer var fbxImporter = FbxImporter.Create(fbxManager, "Importer"); // Initialize the importer. int fileFormat = -1; bool status = fbxImporter.Initialize(LastFilePath, fileFormat, fbxIOSettings); FbxStatus fbxStatus = fbxImporter.GetStatus(); // Get the version number of the FBX file format. int fileMajor = -1, fileMinor = -1, fileRevision = -1; fbxImporter.GetFileVersion(out fileMajor, out fileMinor, out fileRevision); // Check that initialization of the fbxImporter was successful if (!status) { Debug.LogError(string.Format("failed to initialize FbxImporter, error returned {0}", fbxStatus.GetErrorString())); if (fbxStatus.GetCode() == FbxStatus.EStatusCode.eInvalidFileVersion) { Debug.LogError(string.Format("Invalid file version detected\nSDK version: {0}.{1}.{2}\nFile version: {3}.{4}.{5}", sdkMajor, sdkMinor, sdkRevision, fileMajor, fileMinor, fileRevision)); } return(0); } // Import options. Determine what kind of data is to be imported. // The default is true, but here we set the options explictly. fbxIOSettings.SetBoolProp(Globals.IMP_FBX_MATERIAL, false); fbxIOSettings.SetBoolProp(Globals.IMP_FBX_TEXTURE, false); fbxIOSettings.SetBoolProp(Globals.IMP_FBX_ANIMATION, false); fbxIOSettings.SetBoolProp(Globals.IMP_FBX_EXTRACT_EMBEDDED_DATA, false); fbxIOSettings.SetBoolProp(Globals.IMP_FBX_GLOBAL_SETTINGS, true); // Create a scene var fbxScene = FbxScene.Create(fbxManager, "Scene"); // Import the scene to the file. status = fbxImporter.Import(fbxScene); if (status == false) { Debug.LogError(string.Format("failed to import file ({0})", fbxImporter.GetStatus().GetErrorString())); } else { // import data into scene ProcessScene(fbxScene); } // cleanup fbxScene.Destroy(); fbxImporter.Destroy(); return(status == true ? NumNodes : 0); } }
// tests that should work for any subclass of FbxProperty public static void GenericPropertyTests <T>(T property, FbxObject parent, string propertyName, FbxDataType dataType) where T : FbxProperty { Assert.IsTrue(property.IsValid()); Assert.AreEqual(dataType, property.GetPropertyDataType()); Assert.AreEqual(propertyName, property.GetName()); Assert.AreEqual(propertyName, property.ToString()); Assert.AreEqual(propertyName, property.GetHierarchicalName()); Assert.AreEqual(propertyName, property.GetLabel(true)); property.SetLabel("label"); Assert.AreEqual("label", property.GetLabel()); Assert.AreEqual(parent, property.GetFbxObject()); Assert.AreEqual(property.GetFbxObject(), parent); // test it both ways just in case equals is busted // test the flags using the animatable flag property.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true); Assert.IsTrue(property.GetFlag(FbxPropertyFlags.EFlags.eAnimatable)); Assert.AreNotEqual(0, property.GetFlags() | FbxPropertyFlags.EFlags.eAnimatable); property.SetFlagInheritType(FbxPropertyFlags.EFlags.eAnimatable, FbxPropertyFlags.EInheritType.eInherit); Assert.AreEqual(FbxPropertyFlags.EInheritType.eInherit, property.GetFlagInheritType(FbxPropertyFlags.EFlags.eAnimatable)); // not clear when this ever returns true: whether we set animatable // to true or false it says it has the default value. Assert.IsFalse(property.ModifiedFlag(FbxPropertyFlags.EFlags.eAnimatable)); // Test setting the value with the generic float accessor. // The value may not round-trip: a bool property will go to 1.0 property.Set(5.0f); TestGetter(property.GetFloat()); TestGetter(property.GetBool()); TestGetter(property.GetDouble()); TestGetter(property.GetFbxColor()); TestGetter(property.GetFbxDouble3()); TestGetter(property.GetString()); TestGetter(property.GetInt()); // Test setting the value with color accessor property.Set(new FbxColor()); // test GetCurve(). Just make sure it doesn't crash. We can't // generically test actually getting curves, because the details // (channel names etc) depend on the type of property and its // flags. FbxAnimLayer layer = FbxAnimLayer.Create(parent, "layer"); property.GetCurve(layer); property.GetCurve(layer, true); property.GetCurve(layer, "asdf"); property.GetCurve(layer, "asdf", true); property.GetCurve(layer, "asdf", "hjkl", true); Assert.That(() => { property.GetCurve(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>()); // test GetCurveNode() (make sure it doesn't crash) FbxAnimCurveNode curveNode = property.GetCurveNode(); Assert.IsNull(curveNode); // didn't create one so should be null curveNode = property.GetCurveNode(true); // TODO: figure out why the curve node doesn't get created //Assert.IsNotNull (curveNode); property.GetCurveNode(FbxAnimStack.Create(parent, "anim stack")); property.GetCurveNode(FbxAnimStack.Create(parent, "anim stack"), true); property.GetCurveNode(FbxAnimLayer.Create(parent, "anim layer")); property.GetCurveNode(FbxAnimLayer.Create(parent, "anim layer"), true); Assert.That(() => { property.GetCurveNode((FbxAnimStack)null); }, Throws.Exception.TypeOf <System.ArgumentNullException>()); Assert.That(() => { property.GetCurveNode((FbxAnimLayer)null); }, Throws.Exception.TypeOf <System.ArgumentNullException>()); using (FbxManager manager = FbxManager.Create()) { // Test ConnectSrcObject functions FbxObject obj = FbxObject.Create(manager, "obj"); bool result = property.ConnectSrcObject(obj); Assert.IsTrue(result); Assert.IsTrue(property.IsConnectedSrcObject(obj)); Assert.AreEqual(1, property.GetSrcObjectCount()); Assert.AreEqual(obj, property.GetSrcObject()); Assert.AreEqual(obj, property.GetSrcObject(0)); Assert.AreEqual(obj, property.FindSrcObject("obj")); Assert.IsNull(property.FindSrcObject("obj", 1)); Assert.That(() => { property.FindSrcObject(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>()); Assert.IsTrue(property.DisconnectSrcObject(obj)); Assert.IsFalse(property.IsConnectedSrcObject(obj)); Assert.That(() => { property.ConnectSrcObject(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>()); Assert.IsTrue(property.ConnectSrcObject(obj, FbxConnection.EType.eData)); Assert.IsTrue(property.DisconnectAllSrcObject()); // Test ConnectDstObject functions result = property.ConnectDstObject(obj); Assert.IsTrue(result); Assert.IsTrue(property.IsConnectedDstObject(obj)); Assert.AreEqual(1, property.GetDstObjectCount()); Assert.AreEqual(obj, property.GetDstObject()); Assert.AreEqual(obj, property.GetDstObject(0)); Assert.AreEqual(obj, property.FindDstObject("obj")); Assert.IsNull(property.FindDstObject("obj", 1)); Assert.That(() => { property.FindDstObject(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>()); Assert.IsTrue(property.DisconnectDstObject(obj)); Assert.IsFalse(property.IsConnectedDstObject(obj)); Assert.That(() => { property.ConnectDstObject(null); }, Throws.Exception.TypeOf <System.ArgumentNullException>()); Assert.IsTrue(property.ConnectDstObject(obj, FbxConnection.EType.eData)); Assert.IsTrue(property.DisconnectAllDstObject()); } // verify this in the future: will dispose destroy? property.Dispose(); }
public new static FbxCollectionExclusive Create(FbxManager pManager, string pName) { global::System.IntPtr cPtr = fbx_wrapperPINVOKE.FbxCollectionExclusive_Create__SWIG_0(FbxManager.getCPtr(pManager), pName); FbxCollectionExclusive ret = (cPtr == global::System.IntPtr.Zero) ? null : new FbxCollectionExclusive(cPtr, false); return(ret); }
public void TestEquality() { using (var manager = FbxManager.Create()) { // FbxProperty var node = FbxNode.Create(manager, "node"); var prop1 = FbxProperty.Create(node, Globals.FbxBoolDT, "bool1"); var prop2 = FbxProperty.Create(node, Globals.FbxBoolDT, "bool2"); var prop1copy = node.FindProperty("bool1"); EqualityTester <FbxProperty> .TestEquality(prop1, prop2, prop1copy); // FbxPropertyT<bool> var vis1 = node.VisibilityInheritance; var vis2 = FbxNode.Create(manager, "node2").VisibilityInheritance; var vis1copy = vis1; // TODO: node.FindProperty("Visibility Inheritance"); -- but that has a different proxy type EqualityTester <FbxPropertyBool> .TestEquality(vis1, vis2, vis1copy); // FbxPropertyT<EInheritType> var inhType1 = node.InheritType; var inhType2 = FbxNode.Create(manager, "node3").InheritType; var inhType1Copy = inhType1; // TODO: node.FindProperty("InheritType"); EqualityTester <FbxPropertyEInheritType> .TestEquality(inhType1, inhType2, inhType1Copy); // FbxPropertyT<double> var lambert = FbxSurfaceLambert.Create(manager, "lambert"); var emissiveCopy = lambert.EmissiveFactor; // TODO: lambert.FindProperty("EmissiveFactor"); EqualityTester <FbxPropertyDouble> .TestEquality(lambert.EmissiveFactor, lambert.AmbientFactor, emissiveCopy); // FbxPropertyT<FbxDouble3> var lclTranslationCopy = node.LclTranslation; // TODO: node.FindProperty("Lcl Translation"); EqualityTester <FbxPropertyDouble3> .TestEquality(node.LclTranslation, node.LclRotation, lclTranslationCopy); // FbxPropertyT<float> var light = FbxLight.Create(manager, "light"); EqualityTester <FbxPropertyFloat> .TestEquality(light.LeftBarnDoor, light.RightBarnDoor, light.LeftBarnDoor); // FbxPropertyT<int> var constraint = FbxConstraintAim.Create(manager, "constraint"); var constraint2 = FbxConstraintAim.Create(manager, "constraint2"); var worldUpTypeCopy = constraint.WorldUpType; // TODO: constraint.FindProperty("WorldUpType"); EqualityTester <FbxPropertyInt> .TestEquality(constraint.WorldUpType, constraint2.WorldUpType, worldUpTypeCopy); // FbxPropertyT<> for FbxTexture enums var tex1 = FbxTexture.Create(manager, "tex1"); var tex2 = FbxTexture.Create(manager, "tex2"); var blendCopy = tex1.CurrentTextureBlendMode; // TODO: tex1.FindProperty(...) EqualityTester <FbxPropertyEBlendMode> .TestEquality(tex1.CurrentTextureBlendMode, tex2.CurrentTextureBlendMode, blendCopy); var wrapCopy = tex1.WrapModeU; // TODO: tex1.FindProperty(...) EqualityTester <FbxPropertyEWrapMode> .TestEquality(tex1.WrapModeU, tex2.WrapModeU, wrapCopy); // FbxPropertyT<FbxNull.ELook> var null1 = FbxNull.Create(manager, "null1"); var null2 = FbxNull.Create(manager, "null2"); EqualityTester <FbxPropertyNullELook> .TestEquality(null1.Look, null2.Look, null1.Look); // FbxPropertyT<FbxMarker.ELook> var marker1 = FbxMarker.Create(manager, "marker1"); var marker2 = FbxMarker.Create(manager, "marker2"); EqualityTester <FbxPropertyMarkerELook> .TestEquality(marker1.Look, marker2.Look, marker1.Look); // FbxPropertyT<string> var impl = FbxImplementation.Create(manager, "impl"); var renderAPIcopy = impl.RenderAPI; // TODO: impl.FindProperty("RenderAPI"); EqualityTester <FbxPropertyString> .TestEquality(impl.RenderAPI, impl.RenderAPIVersion, renderAPIcopy); // FbxPropertyT<> for FbxCamera enum EProjectionType var cam1 = FbxCamera.Create(manager, "cam1"); var cam2 = FbxCamera.Create(manager, "cam2"); var projectionCopy = cam1.ProjectionType; EqualityTester <FbxPropertyEProjectionType> .TestEquality(cam1.ProjectionType, cam2.ProjectionType, projectionCopy); // FbxPropertyT<> for FbxLight enum EType var light1 = FbxLight.Create(manager, "light1"); var light2 = FbxLight.Create(manager, "light2"); var typeCopy = light1.LightType; EqualityTester <FbxPropertyELightType> .TestEquality(light1.LightType, light2.LightType, typeCopy); var lightShapeCopy = light1.AreaLightShape; EqualityTester <FbxPropertyEAreaLightShape> .TestEquality(light1.AreaLightShape, light2.AreaLightShape, lightShapeCopy); var decayCopy = light1.DecayType; EqualityTester <FbxPropertyEDecayType> .TestEquality(light1.DecayType, light2.DecayType, decayCopy); var floatCopy = light1.LeftBarnDoor; EqualityTester <FbxPropertyFloat> .TestEquality(light1.LeftBarnDoor, light2.LeftBarnDoor, floatCopy); } }
public virtual void Init() { Manager = FbxManager.Create(); }
public void BasicTests() { using (var manager = FbxManager.Create()) { // FbxPropertyT<FbxBool> example: VisibilityInheritance on a node var node = FbxNode.Create(manager, "node"); GenericPropertyTests <FbxPropertyBool> (node.VisibilityInheritance, node, "Visibility Inheritance", Globals.FbxVisibilityInheritanceDT); var property = node.VisibilityInheritance; property.Set(false); Assert.AreEqual(false, property.Get()); Assert.AreEqual(false, property.EvaluateValue()); Assert.AreEqual(false, property.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(false, property.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<FbxDouble> example: several of them on a Lambert shader var obj = FbxSurfaceLambert.Create(manager, "lambert"); GenericPropertyTests <FbxPropertyDouble> (obj.EmissiveFactor, obj, "EmissiveFactor", Globals.FbxDoubleDT); var property = obj.EmissiveFactor; property.Set(5.0); // bool Set<float> is not accessible here! Assert.AreEqual(5.0, property.Get()); Assert.AreEqual(5.0, property.EvaluateValue()); Assert.AreEqual(5.0, property.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(5.0, property.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<Double3> example: the LclTranslation on a node var node = FbxNode.Create(manager, "node"); GenericPropertyTests <FbxPropertyDouble3> (node.LclTranslation, node, "Lcl Translation", Globals.FbxLocalTranslationDT); var property = node.LclTranslation; property.Set(new FbxDouble3(1, 2, 3)); Assert.AreEqual(new FbxDouble3(1, 2, 3), property.Get()); Assert.AreEqual(new FbxDouble3(1, 2, 3), property.EvaluateValue()); Assert.AreEqual(new FbxDouble3(1, 2, 3), property.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(new FbxDouble3(1, 2, 3), property.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<float> example: the LeftBarnDoor on a light var light = FbxLight.Create(manager, "light"); GenericPropertyTests(light.LeftBarnDoor, light, "LeftBarnDoor", Globals.FbxFloatDT); var property = light.LeftBarnDoor; light.LeftBarnDoor.Set(5.0f); Assert.AreEqual(5.0f, light.LeftBarnDoor.Get()); Assert.AreEqual(5.0f, property.EvaluateValue()); Assert.AreEqual(5.0f, property.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(5.0f, property.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<int> example: the WorldUpType on an aim constraint var constraint = FbxConstraintAim.Create(manager, "constraint"); GenericPropertyTests(constraint.WorldUpType, constraint, "WorldUpType", Globals.FbxEnumDT); var property = constraint.WorldUpType; int value = (int)FbxConstraintAim.EWorldUp.eAimAtObjectUp; constraint.WorldUpType.Set(value); Assert.That(constraint.WorldUpType.Get(), Is.EqualTo(value)); Assert.That(property.EvaluateValue(), Is.EqualTo(value)); Assert.That(property.EvaluateValue(FbxTime.FromSecondDouble(5)), Is.EqualTo(value)); Assert.That(property.EvaluateValue(FbxTime.FromSecondDouble(5), true), Is.EqualTo(value)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<FbxString> example: the description of a shader implementation var impl = FbxImplementation.Create(manager, "name"); GenericPropertyTests <FbxPropertyString> (impl.RenderAPI, impl, "RenderAPI", Globals.FbxStringDT); var property = impl.RenderAPI; property.Set("a value"); Assert.AreEqual("a value", property.Get()); // animated strings come out as empty-string Assert.AreEqual("", property.EvaluateValue()); Assert.AreEqual("", property.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual("", property.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT for FbxTexture enums EBlendMode and EWrapMode var tex = FbxTexture.Create(manager, "tex"); FbxPropertyTest.GenericPropertyTests(tex.CurrentTextureBlendMode, tex, "CurrentTextureBlendMode", Globals.FbxEnumDT); tex.CurrentTextureBlendMode.Set(FbxTexture.EBlendMode.eAdditive); Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.Get()); Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.EvaluateValue()); Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxTexture.EBlendMode.eAdditive, tex.CurrentTextureBlendMode.EvaluateValue(FbxTime.FromSecondDouble(5), true)); FbxPropertyTest.GenericPropertyTests(tex.WrapModeU, tex, "WrapModeU", Globals.FbxEnumDT); tex.WrapModeU.Set(FbxTexture.EWrapMode.eClamp); Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.Get()); Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.EvaluateValue()); Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxTexture.EWrapMode.eClamp, tex.WrapModeU.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<FbxNull.ELook> var null1 = FbxNull.Create(manager, "null1"); FbxPropertyTest.GenericPropertyTests(null1.Look, null1, "Look", Globals.FbxEnumDT); null1.Look.Set(FbxNull.ELook.eCross); Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.Get()); Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.EvaluateValue()); Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxNull.ELook.eCross, null1.Look.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<FbxMarker.ELook> var marker1 = FbxMarker.Create(manager, "marker1"); FbxPropertyTest.GenericPropertyTests(marker1.Look, marker1, "Look", Globals.FbxEnumDT); marker1.Look.Set(FbxMarker.ELook.eCapsule); Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.Get()); Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.EvaluateValue()); Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxMarker.ELook.eCapsule, marker1.Look.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT for FbxCamera enum EProjectionType var camera = FbxCamera.Create(manager, "camera"); FbxPropertyTest.GenericPropertyTests(camera.ProjectionType, camera, "CameraProjectionType", Globals.FbxEnumDT); camera.ProjectionType.Set(FbxCamera.EProjectionType.ePerspective); Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.Get()); Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.EvaluateValue()); Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxCamera.EProjectionType.ePerspective, camera.ProjectionType.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT for FbxCamera enum EGateFit var camera = FbxCamera.Create(manager, "camera"); FbxPropertyTest.GenericPropertyTests(camera.GateFit, camera, "GateFit", Globals.FbxEnumDT); camera.GateFit.Set(FbxCamera.EGateFit.eFitHorizontal); Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.Get()); Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.EvaluateValue()); Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxCamera.EGateFit.eFitHorizontal, camera.GateFit.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT<EInheritType> var node = FbxNode.Create(manager, "node"); FbxPropertyTest.GenericPropertyTests(node.InheritType, node, "InheritType", Globals.FbxEnumDT); node.InheritType.Set(FbxTransform.EInheritType.eInheritRSrs); Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.Get()); Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.EvaluateValue()); Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxTransform.EInheritType.eInheritRSrs, node.InheritType.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // FbxPropertyT for FbxLight enums var light = FbxLight.Create(manager, "light"); FbxPropertyTest.GenericPropertyTests(light.LightType, light, "LightType", Globals.FbxEnumDT); light.LightType.Set(FbxLight.EType.eSpot); Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.Get()); Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.EvaluateValue()); Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxLight.EType.eSpot, light.LightType.EvaluateValue(FbxTime.FromSecondDouble(5), true)); FbxPropertyTest.GenericPropertyTests(light.AreaLightShape, light, "AreaLightShape", Globals.FbxEnumDT); light.AreaLightShape.Set(FbxLight.EAreaLightShape.eSphere); Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.Get()); Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.EvaluateValue()); Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxLight.EAreaLightShape.eSphere, light.AreaLightShape.EvaluateValue(FbxTime.FromSecondDouble(5), true)); FbxPropertyTest.GenericPropertyTests(light.DecayType, light, "DecayType", Globals.FbxEnumDT); light.DecayType.Set(FbxLight.EDecayType.eCubic); Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.Get()); Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.EvaluateValue()); Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.EvaluateValue(FbxTime.FromSecondDouble(5))); Assert.AreEqual(FbxLight.EDecayType.eCubic, light.DecayType.EvaluateValue(FbxTime.FromSecondDouble(5), true)); } using (var manager = FbxManager.Create()) { // Test all the create and destroy operations FbxProperty root, child; var obj = FbxObject.Create(manager, "obj"); Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "a")); Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "b", "label")); Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "c", "label", false)); bool didFind; Assert.IsNotNull(FbxProperty.Create(obj, Globals.FbxStringDT, "c", "label", true, out didFind)); Assert.IsTrue(didFind); root = FbxProperty.Create(obj, Globals.FbxCompoundDT, "root"); child = FbxProperty.Create(root, Globals.FbxStringDT, "a"); Assert.IsNotNull(child); Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "b", "label")); Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "c", "label", false)); Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "c", "label", true, out didFind)); Assert.IsTrue(didFind); child.Destroy(); root.DestroyChildren(); Assert.IsNotNull(FbxProperty.Create(root, Globals.FbxStringDT, "c", "label", true, out didFind)); Assert.IsFalse(didFind); root.DestroyRecursively(); } }
public FbxExternalDocRefListener(FbxManager pManager, FbxString pDocFilePath) : this(fbx_wrapperPINVOKE.new_FbxExternalDocRefListener(FbxManager.getCPtr(pManager), FbxString.getCPtr(pDocFilePath)), true) { if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } }
protected override FbxScene CreateScene(FbxManager manager) { FbxScene scene = base.CreateScene(manager); // Add normals, binormals, UVs, tangents and vertex colors to the cube FbxMesh cubeMesh = scene.GetRootNode().GetChild(0).GetMesh(); // Add normals /// Set the Normals on Layer 0. FbxLayer fbxLayer = cubeMesh.GetLayer(0 /* default layer */); if (fbxLayer == null) { cubeMesh.CreateLayer(); fbxLayer = cubeMesh.GetLayer(0 /* default layer */); } using (var fbxLayerElement = FbxLayerElementNormal.Create(cubeMesh, "Normals")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); // Assign the normal vectors in the same order the control points were defined FbxVector4[] normals = { normalZPos, normalXPos, normalZNeg, normalXNeg, normalYPos, normalYNeg }; for (int n = 0; n < normals.Length; n++) { for (int i = 0; i < 4; i++) { fbxElementArray.Add(normals [n]); } } fbxLayer.SetNormals(fbxLayerElement); } /// Set the binormals on Layer 0. using (var fbxLayerElement = FbxLayerElementBinormal.Create(cubeMesh, "Binormals")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < cubeMesh.GetControlPointsCount(); n++) { fbxElementArray.Add(new FbxVector4(-1, 0, 1)); // TODO: set to correct values } fbxLayer.SetBinormals(fbxLayerElement); } /// Set the tangents on Layer 0. using (var fbxLayerElement = FbxLayerElementTangent.Create(cubeMesh, "Tangents")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < cubeMesh.GetControlPointsCount(); n++) { fbxElementArray.Add(new FbxVector4(0, -1, 1)); // TODO: set to correct values } fbxLayer.SetTangents(fbxLayerElement); } // set the vertex colors using (var fbxLayerElement = FbxLayerElementVertexColor.Create(cubeMesh, "VertexColors")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); // Add one normal per each vertex face index (3 per triangle) FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); // make each vertex either black or white for (int n = 0; n < cubeMesh.GetControlPointsCount(); n++) { fbxElementArray.Add(new FbxColor(n % 2, n % 2, n % 2)); } fbxLayer.SetVertexColors(fbxLayerElement); } // set the UVs using (var fbxLayerElement = FbxLayerElementUV.Create(cubeMesh, "UVSet")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect); // set texture coordinates per vertex FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < 8; n++) { fbxElementArray.Add(new FbxVector2(n % 2, 1)); // TODO: switch to correct values } // For each face index, point to a texture uv FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray(); fbxIndexArray.SetCount(24); for (int vertIndex = 0; vertIndex < 24; vertIndex++) { fbxIndexArray.SetAt(vertIndex, vertIndex % 8); // TODO: switch to correct values } fbxLayer.SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse); } return(scene); }
public void TestBasics() { Assert.That(!string.IsNullOrEmpty(ModelExporter.GetVersionFromReadme())); // Test GetOrCreateLayer using (var fbxManager = FbxManager.Create()) { var fbxMesh = FbxMesh.Create(fbxManager, "name"); var layer0 = ModelExporter.GetOrCreateLayer(fbxMesh); Assert.That(layer0, Is.Not.Null); Assert.That(ModelExporter.GetOrCreateLayer(fbxMesh), Is.EqualTo(layer0)); var layer5 = ModelExporter.GetOrCreateLayer(fbxMesh, layer: 5); Assert.That(layer5, Is.Not.Null); Assert.That(layer5, Is.Not.EqualTo(layer0)); } // Test axis conversion: a x b in left-handed is the same as b x a // in right-handed (that's why we need to flip the winding order). var a = new Vector3(1, 0, 0); var b = new Vector3(0, 0, 1); var crossLeft = Vector3.Cross(a, b); Assert.That(ModelExporter.DefaultMaterial); // Test non-static functions. using (var fbxManager = FbxManager.Create()) { var fbxScene = FbxScene.Create(fbxManager, "scene"); var fbxNode = FbxNode.Create(fbxScene, "node"); var exporter = new ModelExporter(); // Test ExportMaterial: it exports and it re-exports bool result = exporter.ExportMaterial(ModelExporter.DefaultMaterial, fbxScene, fbxNode); Assert.IsTrue(result); var fbxMaterial = fbxNode.GetMaterial(0); Assert.That(fbxMaterial, Is.Not.Null); result = exporter.ExportMaterial(ModelExporter.DefaultMaterial, fbxScene, fbxNode); var fbxMaterial2 = fbxNode.GetMaterial(1); Assert.AreEqual(fbxMaterial, fbxMaterial2); // Test ExportTexture: it finds the same texture for the default-material (it doesn't create a new one) var fbxMaterialNew = FbxSurfaceLambert.Create(fbxScene, "lambert"); exporter.ExportTexture(ModelExporter.DefaultMaterial, "_MainTex", fbxMaterialNew, FbxSurfaceLambert.sBump); Assert.AreEqual( fbxMaterial.FindProperty(FbxSurfaceLambert.sDiffuse).GetSrcObject(), fbxMaterialNew.FindProperty(FbxSurfaceLambert.sBump).GetSrcObject() ); // Test ExportMesh: make sure we exported a mesh with welded vertices. var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); var cubeNode = FbxNode.Create(fbxScene, "cube"); exporter.ExportMesh(cube.GetComponent <MeshFilter>().sharedMesh, cubeNode); Assert.That(cubeNode.GetMesh(), Is.Not.Null); Assert.That(cubeNode.GetMesh().GetControlPointsCount(), Is.EqualTo(8)); } // Test exporting a skinned-mesh. Make sure it doesn't leak (it did at one point) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); var character = new GameObject(); var smr = character.AddComponent <SkinnedMeshRenderer>(); smr.sharedMesh = cube.GetComponent <MeshFilter>().sharedMesh; var meshCount = Object.FindObjectsOfType <Mesh>().Length; ModelExporter.ExportObject(GetRandomFbxFilePath(), character); Assert.AreEqual(meshCount, Object.FindObjectsOfType <Mesh>().Length); } // Test euler to quaternion conversion { // EulerToQuaternionZXY var v = new Vector3(50, 45, 190); var quat = ModelExporter.EulerToQuaternionZXY(v); var unityQuat = Quaternion.Euler(v); Assert.That((float)quat.X, Is.EqualTo(unityQuat.x)); Assert.That((float)quat.Y, Is.EqualTo(unityQuat.y)); Assert.That((float)quat.Z, Is.EqualTo(unityQuat.z)); Assert.That((float)quat.W, Is.EqualTo(unityQuat.w)); // EulerToQuaternionXYZ var fbxV = new FbxVector4(v.x, v.y, v.z); var xyzQuat = ModelExporter.EulerToQuaternionXYZ(fbxV); // get the vector from the quaternion FbxAMatrix m = new FbxAMatrix(); m.SetR(fbxV); var actualQuat = m.GetQ(); // since this quaternion is XYZ instead of ZXY, it should not match the quaternion // created with EulerToQuaternionZXY Assert.That(xyzQuat, Is.Not.EqualTo(quat)); Assert.That(xyzQuat, Is.EqualTo(actualQuat)); } }
protected override FbxScene CreateScene(FbxManager manager) { FbxScene scene = base.CreateScene(manager); // Set the UVs FbxMesh cubeMesh = scene.GetRootNode().GetChild(0).GetMesh(); FbxLayer fbxLayer = cubeMesh.GetLayer(0 /* default layer */); if (fbxLayer == null) { cubeMesh.CreateLayer(); fbxLayer = cubeMesh.GetLayer(0 /* default layer */); } using (var fbxLayerElement = FbxLayerElementUV.Create(cubeMesh, "UVSet")) { fbxLayerElement.SetMappingMode(FbxLayerElement.EMappingMode.eByPolygonVertex); fbxLayerElement.SetReferenceMode(FbxLayerElement.EReferenceMode.eIndexToDirect); // set texture coordinates per vertex FbxLayerElementArray fbxElementArray = fbxLayerElement.GetDirectArray(); for (int n = 0; n < 8; n++) { fbxElementArray.Add(new FbxVector2(n % 2, 1)); // TODO: switch to correct values } // For each face index, point to a texture uv FbxLayerElementArray fbxIndexArray = fbxLayerElement.GetIndexArray(); fbxIndexArray.SetCount(24); for (int vertIndex = 0; vertIndex < 24; vertIndex++) { fbxIndexArray.SetAt(vertIndex, vertIndex % 8); // TODO: switch to correct values } fbxLayer.SetUVs(fbxLayerElement, FbxLayerElement.EType.eTextureDiffuse); } // Create the material var fbxMaterial = FbxSurfacePhong.Create(scene, m_materialName); fbxMaterial.Diffuse.Set(new FbxColor(1, 1, 1)); fbxMaterial.Emissive.Set(new FbxColor(0.5, 0.1, 0.2)); fbxMaterial.Ambient.Set(new FbxDouble3(0.3, 0.4, 0)); fbxMaterial.BumpFactor.Set(0.6); fbxMaterial.Specular.Set(new FbxDouble3(0.8, 0.7, 0.9)); // Create and add the texture var fbxMaterialProperty = fbxMaterial.FindProperty(FbxSurfaceMaterial.sDiffuse); Assert.IsNotNull(fbxMaterialProperty); Assert.IsTrue(fbxMaterialProperty.IsValid()); var fbxTexture = FbxFileTexture.Create(fbxMaterial, FbxSurfaceMaterial.sDiffuse + "_Texture"); fbxTexture.SetFileName("/path/to/some/texture.jpg"); fbxTexture.SetTextureUse(FbxTexture.ETextureUse.eStandard); fbxTexture.SetMappingType(FbxTexture.EMappingType.eUV); fbxTexture.ConnectDstProperty(fbxMaterialProperty); scene.GetRootNode().GetChild(0).AddMaterial(fbxMaterial); return(scene); }
// Start is called before the first frame update void Start() { #if FBXSDK_RUNTIME // Build the fbx scene file path // (player/player_data/emptySceneFromRuntime.fbx) string fbxFilePath = Application.dataPath; fbxFilePath = Path.Combine(fbxFilePath, "emptySceneFromRuntimeBuild.fbx"); fbxFilePath = Path.GetFullPath(fbxFilePath); Debug.Log(string.Format("The file that will be written is {0}", fbxFilePath)); using (var fbxManager = FbxManager.Create()) { FbxIOSettings fbxIOSettings = FbxIOSettings.Create(fbxManager, Globals.IOSROOT); // Configure the IO settings. fbxManager.SetIOSettings(fbxIOSettings); // Create the exporter var fbxExporter = FbxExporter.Create(fbxManager, "Exporter"); // Initialize the exporter. int fileFormat = fbxManager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)"); bool status = fbxExporter.Initialize(fbxFilePath, fileFormat, fbxIOSettings); // Check that initialization of the fbxExporter was successful if (!status) { Debug.LogError(string.Format("failed to initialize exporter, reason: {0}", fbxExporter.GetStatus().GetErrorString())); return; } // 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 = "fromRuntime"; fbxSceneInfo.mSubject = "Exported from a Unity runtime"; fbxSceneInfo.mAuthor = "Unity Technologies"; fbxSceneInfo.mRevision = "1.0"; fbxSceneInfo.mKeywords = "export runtime"; fbxSceneInfo.mComment = "This is to demonstrate the capability of exporting from a Unity runtime, using the FBX SDK C# bindings"; fbxScene.SetSceneInfo(fbxSceneInfo); // Export the scene to the file. status = fbxExporter.Export(fbxScene); // cleanup fbxScene.Destroy(); fbxExporter.Destroy(); } #endif // Immediately close the standalone application after // exporting the FBX Application.Quit(); }
public static new FbxAnimCurve Create(FbxManager pManager, string pName) { throw new System.NotImplementedException("FbxAnimCurve can only be created with a scene as argument."); }
//static bool ContainsMeshesRecursive( Node node ) //{ // if( node.HasMeshes ) // return true; // foreach( var child in node.Children ) // { // if( ContainsMeshesRecursive( child ) ) // return true; // } // return false; //} public static void DoImport(Settings settings, out string error) { error = "(NO ERROR MESSAGE)"; 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(settings.virtualFileName); //VirtualFileStream stream = null; //ToDo : FromStream bool status; if (!string.IsNullOrEmpty(realFileName) && File.Exists(realFileName)) { status = importer.Initialize(realFileName, -1, setting); } else { error = "File is not exists."; return; //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; } scene = FbxScene.Create(manager, "scene1"); status = importer.Import(scene); if (!status) { return; } error = ""; var importContext = new ImportContext(); importContext.manager = manager; importContext.scene = scene; importContext.settings = settings; importContext.directoryName = Path.GetDirectoryName(settings.virtualFileName); ImportScene(importContext); ////create meshes (Scene mode) //if( settings.component.Mode.Value == Component_Import3D.ModeEnum.Scene /*&& scene.HasMeshes && scene.MeshCount != 0 */) //{ // importContext.meshesGroup = settings.component.GetComponentByName( "Meshes" ) as Component_Mesh; // if( importContext.meshesGroup == null ) // { // importContext.meshesGroup = settings.component.CreateComponent<Component>( -1, false ); // importContext.meshesGroup.Name = "Meshes"; // } // else // importContext.meshesGroup.Enabled = false; //} ////enable groups //if( importContext.meshesGroup != null ) // importContext.meshesGroup.Enabled = true; //if( importContext.sceneObjectsGroup != null ) // importContext.sceneObjectsGroup.Enabled = true; //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 { } } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FbxManager obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }