Skip to content

Commit e07e23f

Browse files
committed
Fixing PBShape export using FBX Exporter
1 parent 29f96cb commit e07e23f

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

Addons/Fbx.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reflection;
55
using System.Linq;
66
using UnityEditor.ProBuilder;
7+
using UnityEditor.ProBuilder.Actions;
78

89
namespace UnityEngine.ProBuilder.Addons.FBX
910
{
@@ -40,13 +41,6 @@ private static Assembly FbxExporterAssembly
4041
}
4142
}
4243
}
43-
44-
static readonly Type[] k_ProBuilderTypes = new Type[]
45-
{
46-
typeof(BezierShape),
47-
typeof(PolyShape),
48-
typeof(Entity)
49-
};
5044

5145
static FbxOptions m_FbxOptions = new FbxOptions() {
5246
quads = true
@@ -71,12 +65,12 @@ static void TryLoadFbxSupport()
7165
var getMeshForComponent = FbxExporterAssembly.GetTypes()
7266
.Where(t => t.BaseType == typeof(MulticastDelegate) && t.Name.StartsWith("GetMeshForComponent"))
7367
.First(t => t.ContainsGenericParameters);
74-
68+
7569
getMeshForComponent = getMeshForComponent.MakeGenericType(typeof(ProBuilderMesh));
7670
var meshDelegate = Delegate.CreateDelegate(getMeshForComponent, typeof(Fbx).GetMethod("GetMeshForComponent", BindingFlags.NonPublic | BindingFlags.Static));
7771

7872
registerMeshCallback.Invoke(null, new object[] { meshDelegate, true });
79-
73+
8074
m_FbxOptions.quads = ProBuilderSettings.Get<bool>("Export::m_FbxQuads", SettingsScope.User, true);
8175
}
8276

@@ -93,17 +87,17 @@ static bool GetMeshForComponent(object exporter, ProBuilderMesh pmesh, object no
9387

9488
Object.DestroyImmediate(mesh);
9589

96-
// probuilder can't handle mesh assets that may be externally reloaded, just strip pb stuff for now.
97-
foreach (var type in k_ProBuilderTypes)
90+
var exporterType = exporter.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
91+
.First(x => x.Name == "get_ExportOptions").Invoke(exporter, null).GetType();
92+
93+
var prefabExporterType = FbxExporterAssembly.GetType("UnityEditor.Formats.Fbx.Exporter.ConvertToPrefabSettingsSerialize");
94+
95+
if(exporterType == prefabExporterType)
9896
{
99-
var component = pmesh.GetComponent(type);
100-
if (component != null)
101-
Object.DestroyImmediate(component);
97+
// probuilder can't handle mesh assets that may be externally reloaded, just strip pb stuff for now.
98+
StripProBuilderScripts.DoStrip(pmesh);
10299
}
103100

104-
pmesh.preserveMeshAssetOnDestroy = true;
105-
Object.DestroyImmediate(pmesh);
106-
107101
return true;
108102
}
109103
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Bug Fixes
1111

12+
- [case: 1334017] Fixed errors while exporting a PBShape using FBX Exporter and cleaning export.
1213
- [case: 1332226] Fixed issue where some Gizmos menu items would be missing in projects that have ProBuilder package installed.
1314
- [case: 1324374] Fixed incorrect vertex/edge/face rect selection when mesh's parent is rotated and/or scaled.
1415

0 commit comments

Comments
 (0)