Skip to content

Commit

Permalink
cleanup callbacks, expose ExportNormalTextureInfo, remove temporary A…
Browse files Browse the repository at this point in the history
…fterMaterialExportShouldExportTexture callback
  • Loading branch information
hybridherbst committed Feb 3, 2022
1 parent 3b591e8 commit f59a018
Showing 1 changed file with 5 additions and 32 deletions.
37 changes: 5 additions & 32 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public ExportOptions()
public GLTFSceneExporter.AfterSceneExportDelegate AfterSceneExport;
public GLTFSceneExporter.BeforeSceneExportDelegate BeforeSceneExport;
public GLTFSceneExporter.AfterNodeExportDelegate AfterNodeExport;
public GLTFSceneExporter.BeforeMaterialExport BeforeMaterialExport;
public GLTFSceneExporter.AfterMaterialExport AfterMaterialExport;
public GLTFSceneExporter.AfterMaterialExportShouldExportTexture AfterMaterialExportShouldExportTexture;
public GLTFSceneExporter.BeforeMaterialExportDelegate BeforeMaterialExport;
public GLTFSceneExporter.AfterMaterialExportDelegate AfterMaterialExport;
}

public class GLTFSceneExporter
Expand All @@ -53,9 +52,8 @@ public class GLTFSceneExporter
public delegate void AfterSceneExportDelegate(GLTFSceneExporter exporter, GLTFRoot gltfRoot);
public delegate void AfterNodeExportDelegate(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Transform transform, Node node);
// return true here to signal that material export is complete, no regular export will happen then
public delegate bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode);
public delegate void AfterMaterialExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode);
public delegate bool AfterMaterialExportShouldExportTexture(Material material, string texturePropertyName);
public delegate bool BeforeMaterialExportDelegate(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode);
public delegate void AfterMaterialExportDelegate(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode);

public Texture GetTexture(int id) => _textures[id];

Expand Down Expand Up @@ -1539,31 +1537,6 @@ private MaterialId ExportMaterial(Material materialObj)
material.DoubleSided = true;
}

if (_exportOptions.AfterMaterialExportShouldExportTexture != null)
{
var textureProps = materialObj.GetTexturePropertyNames();
foreach (var name in textureProps)
{
if (_exportOptions.AfterMaterialExportShouldExportTexture == null) break;
if (_exportOptions.AfterMaterialExportShouldExportTexture.Invoke(materialObj, name))
{
var tex = materialObj.GetTexture(name);
if (tex)
{
var hasImporter = TryGetImporter<TextureImporter>(tex, out var importer);
if (hasImporter && importer.textureType == TextureImporterType.NormalMap)
{
ExportNormalTextureInfo(tex, TextureMapType.Bump, materialObj);
}
else
{
ExportTexture(tex, TextureMapType.Custom_Unknown);
}
}
}
}
}

// after material export
if (_exportOptions.AfterMaterialExport != null)
{
Expand Down Expand Up @@ -1787,7 +1760,7 @@ private void ExportTextureTransform(TextureInfo def, Material mat, string texNam
);
}

private NormalTextureInfo ExportNormalTextureInfo(
public NormalTextureInfo ExportNormalTextureInfo(
Texture texture,
TextureMapType textureMapType,
Material material)
Expand Down

0 comments on commit f59a018

Please sign in to comment.