When I first exported a sample .nwd model to FBX for use in Unity, I was very surprised to see that the size was nearly 4 times larger than the size of original file. Looking at the internal parameters of the .fbx file to see what is taking up so much space, the value of MappingInformationType is ByPolygonVertex, so one data value is mapped to each vertex of the polygon, and ReferenceInformationType is Direct, so if there is a lot of data duplication, all normal vectors are It seems that the size of the file has increased after defining it. Is there a way to change these two parameters when export? FBX output is being used by modifying the format previously found on the forum.
namespace FBXPlugin
{
public class FBX_Plugin : CustomPlugin
{
public int Execute()
{
ModelItemCollection model_sub = new ModelItemCollection();
ModelItemCollection model_main = new ModelItemCollection();
foreach (ModelItem item in Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems)
{
var cont = item.Children;
model_main.AddRange(cont);
string fol = @"C:\FBXTest\";
foreach (ModelItem item1 in model_main)
{
string result = null;
result = item1.DisplayName.ToString();
Task.Delay(1000);
model_sub.AddRange(item1.Self);
Task.Delay(1000);
model_sub.Invert(Autodesk.Navisworks.Api.Application.ActiveDocument);
Task.Delay(1000);
Autodesk.Navisworks.Api.Application.ActiveDocument.Models.SetHidden(model_sub, true);
Task.Delay(1000);
PluginRecord FBXPluginrecord = Autodesk.Navisworks.Api.Application.Plugins.FindPlugin("NativeExportPluginAdaptor_LcFbxExporterPlugin_Export.Navisworks");
if (FBXPluginrecord != null)
{
if (!FBXPluginrecord.IsLoaded)
{
FBXPluginrecord.LoadPlugin();
}
string pa = fol+result.Replace(':', '_') + ".fbx";
NativeExportPluginAdaptor FBXplugin = FBXPluginrecord.LoadedPlugin as NativeExportPluginAdaptor;
FBXplugin.Execute(pa);
Task.Delay(1000);
Autodesk.Navisworks.Api.Application.ActiveDocument.Models.SetHidden(model_sub, false);
model_sub.Clear();
Task.Delay(1000);
model_sub.Clear();
}
}
}
return 0;
}
}
}
And this Python code does exactly what I want to add in C#
import fbx
import sys
def simplify_mapping_and_reference(file_path, output_path):
manager = fbx.FbxManager.Create()
ios = fbx.FbxIOSettings.Create(manager, fbx.IOSROOT)
manager.SetIOSettings(ios)
importer = fbx.FbxImporter.Create(manager, "")
if not importer.Initialize(file_path, -1, manager.GetIOSettings()):
print("Error: importer init fail", file_path)
sys.exit(1)
scene = fbx.FbxScene.Create(manager, "Scene")
importer.Import(scene)
importer.Destroy()
root_node = scene.GetRootNode()
if root_node:
for i in range(root_node.GetChildCount()):
node = root_node.GetChild(i)
geometry = node.GetGeometry()
if geometry:
model_count += 1
normal_element = geometry.GetElementNormal()
if normal_element:
normal_element.SetMappingMode(fbx.FbxLayerElement.eByPolygon)
normal_element.SetReferenceMode(fbx.FbxLayerElement.eIndexToDirect)
uv_element = geometry.GetElementUV()
if uv_element:
uv_element.SetMappingMode(fbx.FbxLayerElement.eByPolygon)
uv_element.SetReferenceMode(fbx.FbxLayerElement.eIndexToDirect)
material_element = geometry.GetElementMaterial()
if material_element:
material_element.SetMappingMode(fbx.FbxLayerElement.eByPolygon)
material_element.SetReferenceMode(fbx.FbxLayerElement.eIndexToDirect)
exporter = fbx.FbxExporter.Create(manager, "")
if not exporter.Initialize(output_path, -1, manager.GetIOSettings()):
print("Error: Unable to initialize exporter with file", output_path)
sys.exit(1)
# file export
exporter.Export(scene)
exporter.Destroy()
manager.Destroy()
original_model = "sample_model.fbx"
edited_model = "sample_model_edit.fbx"
simplify_mapping_and_reference(original_model, edited_model)
Can't find what you're looking for? Ask the community or share your knowledge.