Skip to content

Commit 9a8d675

Browse files
authored
Merge pull request #544 from BabylonJS/MayaCoating
Maya and Max PBR Workflow options
2 parents 588b7bd + 3457c45 commit 9a8d675

File tree

14 files changed

+1181
-619
lines changed

14 files changed

+1181
-619
lines changed

3ds Max/Max2Babylon/ExportParameters.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ public class ExportParameters
2020
public bool enableKHRLightsPunctual = false;
2121
public bool enableKHRTextureTransform = false;
2222
public bool enableKHRMaterialsUnlit = false;
23-
public Autodesk.Max.IINode exportNode;
23+
public bool pbrFull = false;
24+
public bool pbrNoLight = false;
25+
public string pbrEnvironment;
2426

27+
public Autodesk.Max.IINode exportNode;
2528

2629
public const string ModelFilePathProperty = "modelFilePathProperty";
2730
public const string TextureFolderPathProperty = "textureFolderPathProperty";
31+
32+
public const string PBRFullPropertyName = "babylonjs_pbr_full";
33+
public const string PBRNoLightPropertyName = "babylonjs_pbr_nolight";
34+
public const string PBREnvironmentPathPropertyName = "babylonjs_pbr_environmentPathProperty";
2835
}
2936
}

3ds Max/Max2Babylon/Exporter/BabylonExporter.Material.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ private void ExportMaterial(IIGameMaterial materialNode, BabylonScene babylonSce
463463
var propertyContainer = materialNode.IPropertyContainer;
464464
var babylonMaterial = new BabylonPBRMetallicRoughnessMaterial(id)
465465
{
466+
maxGameMaterial = materialNode,
466467
name = name,
467468
isUnlit = isUnlit
468469
};
@@ -631,8 +632,17 @@ private void ExportMaterial(IIGameMaterial materialNode, BabylonScene babylonSce
631632
babylonMaterial.roughness = 1.0f;
632633
}
633634

634-
// Add the material to the scene
635-
babylonScene.MaterialsList.Add(babylonMaterial);
635+
if (exportParameters.pbrFull)
636+
{
637+
var fullPBR = new BabylonPBRMaterial(babylonMaterial);
638+
fullPBR.maxGameMaterial = babylonMaterial.maxGameMaterial;
639+
babylonScene.MaterialsList.Add(fullPBR);
640+
}
641+
else
642+
{
643+
// Add the material to the scene
644+
babylonScene.MaterialsList.Add(babylonMaterial);
645+
}
636646
}
637647
else
638648
{

3ds Max/Max2Babylon/Exporter/BabylonExporter.cs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void Export(ExportParameters exportParameters)
209209

210210
babylonScene.gravity = rawScene.GetVector3Property("babylonjs_gravity");
211211
ExportQuaternionsInsteadOfEulers = rawScene.GetBoolProperty("babylonjs_exportquaternions", 1);
212-
if (Loader.Core.UseEnvironmentMap && Loader.Core.EnvironmentMap != null)
212+
if (string.IsNullOrEmpty(exportParameters.pbrEnvironment) && Loader.Core.UseEnvironmentMap && Loader.Core.EnvironmentMap != null)
213213
{
214214
// Environment texture
215215
var environmentMap = Loader.Core.EnvironmentMap;
@@ -224,6 +224,11 @@ public void Export(ExportParameters exportParameters)
224224
babylonScene.skyboxBlurLevel = rawScene.GetFloatProperty("babylonjs_skyboxBlurLevel");
225225
}
226226
}
227+
else if (!string.IsNullOrEmpty(exportParameters.pbrEnvironment))
228+
{
229+
babylonScene.createDefaultSkybox = rawScene.GetBoolProperty("babylonjs_createDefaultSkybox");
230+
babylonScene.skyboxBlurLevel = rawScene.GetFloatProperty("babylonjs_skyboxBlurLevel");
231+
}
227232

228233
// Instantiate custom material exporters
229234
materialExporters = new Dictionary<ClassIDWrapper, IMaterialExporter>();
@@ -343,7 +348,7 @@ public void Export(ExportParameters exportParameters)
343348

344349
// Default light
345350
bool addDefaultLight = rawScene.GetBoolProperty("babylonjs_addDefaultLight", 1);
346-
if (addDefaultLight && babylonScene.LightsList.Count == 0)
351+
if (!exportParameters.pbrNoLight && addDefaultLight && babylonScene.LightsList.Count == 0)
347352
{
348353
RaiseWarning("No light defined", 1);
349354
RaiseWarning("A default hemispheric light was added for your convenience", 1);
@@ -471,6 +476,39 @@ public void Export(ExportParameters exportParameters)
471476
}
472477
}
473478
}
479+
480+
var sourcePath = exportParameters.pbrEnvironment;
481+
if (!string.IsNullOrEmpty(sourcePath)) {
482+
var fileName = Path.GetFileName(sourcePath);
483+
484+
// Allow only dds file format
485+
if (!fileName.EndsWith(".dds"))
486+
{
487+
RaiseWarning("Failed to export defauenvironment texture: only .dds format is supported.");
488+
}
489+
else
490+
{
491+
RaiseMessage($"texture id = Max_Babylon_Default_Environment");
492+
babylonScene.environmentTexture = fileName;
493+
494+
if (exportParameters.writeTextures)
495+
{
496+
try
497+
{
498+
var destPath = Path.Combine(babylonScene.OutputPath, fileName);
499+
if (File.Exists(sourcePath) && sourcePath != destPath)
500+
{
501+
File.Copy(sourcePath, destPath, true);
502+
}
503+
}
504+
catch
505+
{
506+
// silently fails
507+
RaiseMessage($"Fail to export the default env texture", 3);
508+
}
509+
}
510+
}
511+
}
474512
}
475513

476514

0 commit comments

Comments
 (0)