Skip to content

Commit 3457c45

Browse files
committed
Add Maya Babylon PBR options
1 parent c77a453 commit 3457c45

File tree

5 files changed

+733
-534
lines changed

5 files changed

+733
-534
lines changed

Maya/Exporter/BabylonExporter.Material.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ partial class BabylonExporter
1919
/// </summary>
2020
readonly Dictionary<string, List<MFnDependencyNode>> multiMaterials = new Dictionary<string, List<MFnDependencyNode>>();
2121

22-
private void ExportMultiMaterial(string uuidMultiMaterial, List<MFnDependencyNode> materials, BabylonScene babylonScene)
22+
private void ExportMultiMaterial(string uuidMultiMaterial, List<MFnDependencyNode> materials, BabylonScene babylonScene, bool fullPBR)
2323
{
2424
var babylonMultimaterial = new BabylonMultiMaterial { id = uuidMultiMaterial };
2525

@@ -51,15 +51,15 @@ private void ExportMultiMaterial(string uuidMultiMaterial, List<MFnDependencyNod
5151
{
5252
// Export sub material
5353
referencedMaterials.Add(subMat);
54-
ExportMaterial(subMat, babylonScene);
54+
ExportMaterial(subMat, babylonScene, fullPBR);
5555
}
5656
}
5757
babylonMultimaterial.materials = uuids.ToArray();
5858

5959
babylonScene.MultiMaterialsList.Add(babylonMultimaterial);
6060
}
6161

62-
private void ExportMaterial(MFnDependencyNode materialDependencyNode, BabylonScene babylonScene)
62+
private void ExportMaterial(MFnDependencyNode materialDependencyNode, BabylonScene babylonScene, bool fullPBR)
6363
{
6464
MObject materialObject = materialDependencyNode.objectProperty;
6565
var name = materialDependencyNode.name;
@@ -526,7 +526,15 @@ private void ExportMaterial(MFnDependencyNode materialDependencyNode, BabylonSce
526526
}
527527
}
528528

529-
babylonScene.MaterialsList.Add(babylonMaterial);
529+
if (fullPBR)
530+
{
531+
var fullPBRMaterial = new BabylonPBRMaterial(babylonMaterial);
532+
babylonScene.MaterialsList.Add(fullPBRMaterial);
533+
}
534+
else
535+
{
536+
babylonScene.MaterialsList.Add(babylonMaterial);
537+
}
530538
}
531539
else
532540
{

Maya/Exporter/BabylonExporter.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ internal partial class BabylonExporter
6969
public void Export(string outputDirectory, string outputFileName, string outputFormat, bool generateManifest,
7070
bool onlySelected, bool autoSaveMayaFile, bool exportHiddenObjects, bool copyTexturesToOutput,
7171
bool optimizeVertices, bool exportTangents, string scaleFactor, bool exportSkin, string quality, bool dracoCompression,
72-
bool exportMorphNormal, bool exportMorphTangent, bool exportKHRLightsPunctual, bool exportKHRTextureTransform, bool bakeAnimationFrames)
72+
bool exportMorphNormal, bool exportMorphTangent, bool exportKHRLightsPunctual, bool exportKHRTextureTransform, bool bakeAnimationFrames,
73+
bool fullPBR, bool noAutoLight, bool defaultSkybox, string environmentName)
7374
{
7475
// Check if the animation is running
7576
MGlobal.executeCommand("play -q - state", out int isPlayed);
@@ -350,7 +351,7 @@ public void Export(string outputDirectory, string outputFileName, string outputF
350351
}
351352

352353
// Default light
353-
if (babylonScene.LightsList.Count == 0)
354+
if (!noAutoLight && babylonScene.LightsList.Count == 0)
354355
{
355356
RaiseWarning("No light defined", 1);
356357
RaiseWarning("A default ambient light was added for your convenience", 1);
@@ -404,12 +405,12 @@ public void Export(string outputDirectory, string outputFileName, string outputF
404405
GenerateMaterialDuplicationDatas(babylonScene);
405406
foreach (var mat in referencedMaterials)
406407
{
407-
ExportMaterial(mat, babylonScene);
408+
ExportMaterial(mat, babylonScene, fullPBR);
408409
CheckCancelled();
409410
}
410411
foreach (var mat in multiMaterials)
411412
{
412-
ExportMultiMaterial(mat.Key, mat.Value, babylonScene);
413+
ExportMultiMaterial(mat.Key, mat.Value, babylonScene, fullPBR);
413414
CheckCancelled();
414415
}
415416
UpdateMeshesMaterialId(babylonScene);
@@ -462,9 +463,44 @@ public void Export(string outputDirectory, string outputFileName, string outputF
462463
}
463464
}
464465

465-
466466
// Output
467467
babylonScene.Prepare(false, false);
468+
469+
var sourcePath = environmentName;
470+
if (!string.IsNullOrEmpty(sourcePath))
471+
{
472+
babylonScene.createDefaultSkybox = defaultSkybox;
473+
var fileName = Path.GetFileName(sourcePath);
474+
475+
// Allow only dds file format
476+
if (!fileName.EndsWith(".dds"))
477+
{
478+
RaiseWarning("Failed to export defauenvironment texture: only .dds format is supported.");
479+
}
480+
else
481+
{
482+
RaiseMessage($"texture id = Max_Babylon_Default_Environment");
483+
babylonScene.environmentTexture = fileName;
484+
485+
if (copyTexturesToOutput)
486+
{
487+
try
488+
{
489+
var destPath = Path.Combine(babylonScene.OutputPath, fileName);
490+
if (File.Exists(sourcePath) && sourcePath != destPath)
491+
{
492+
File.Copy(sourcePath, destPath, true);
493+
}
494+
}
495+
catch
496+
{
497+
// silently fails
498+
RaiseMessage($"Fail to export the default env texture", 3);
499+
}
500+
}
501+
}
502+
}
503+
468504
if (isBabylonExported)
469505
{
470506
Write(babylonScene, outputBabylonDirectory, outputFileName, outputFormat, generateManifest);

0 commit comments

Comments
 (0)