Skip to content

Commit 58294f6

Browse files
authored
Merge pull request #538 from BabylonJS/NormalBumpSupport
Fix #472 : add NormalBumpTex support
2 parents 01f05f6 + 86a5e75 commit 58294f6

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

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

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,76 @@ private BabylonTexture ExportEnvironmnentTexture(ITexmap texMap, BabylonScene ba
511511
// -- Export sub methods ---
512512
// -------------------------
513513

514+
private ITexmap _getSpecialTexmap(ITexmap texMap, out float amount)
515+
{
516+
if (texMap.ClassName == "Normal Bump")
517+
{
518+
var block = texMap.GetParamBlockByID(0); // General Block
519+
if (block != null)
520+
{
521+
amount = block.GetFloat(0, 0, 0); // Normal texture Mult Spin
522+
var map = block.GetTexmap(2, 0, 0); // Normal texture
523+
var mapEnabled = block.GetInt(4, 0, 0); // Normal texture Enable
524+
if (mapEnabled == 0)
525+
{
526+
RaiseError($"Only Normal Bump Texture with Normal enabled are supported.", 2);
527+
return null;
528+
}
529+
530+
var method = block.GetInt(6, 0, 0); // Normal texture mode (Tangent, screen...)
531+
if (method != 0)
532+
{
533+
RaiseError($"Only Normal Bump Texture in tangent space are supported.", 2);
534+
return null;
535+
}
536+
var flipR = block.GetInt(7, 0, 0); // Normal texture Red chanel Flip
537+
if (flipR != 0)
538+
{
539+
RaiseError($"Only Normal Bump Texture without R flip are supported.", 2);
540+
return null;
541+
}
542+
var flipG = block.GetInt(8, 0, 0); // Normal texture Green chanel Flip
543+
if (flipG != 0)
544+
{
545+
RaiseError($"Only Normal Bump Texture without G flip are supported.", 2);
546+
return null;
547+
}
548+
var swapRG = block.GetInt(9, 0, 0); // Normal texture swap R and G channels
549+
if (swapRG != 0)
550+
{
551+
RaiseError($"Only Normal Bump Texture without R and G swap are supported.", 2);
552+
return null;
553+
}
554+
555+
// var bumpAmount = block.GetFloat(1, 0, 0); // Bump texture Mult Spin
556+
// var bumpMap = block.GetMap(3, 0, 0); // Bump texture
557+
var bumpMapEnable = block.GetInt(5, 0, 0); // Bump texture Enable
558+
if (bumpMapEnable == 1)
559+
{
560+
RaiseError($"Only Normal Bump Texture without Bump are supported.", 2);
561+
return null;
562+
}
563+
564+
return map;
565+
}
566+
}
567+
568+
amount = 0.0f;
569+
RaiseError($"Texture type is not supported. Use a Bitmap or Normal Bump map instead.", 2);
570+
return null;
571+
}
572+
514573
private BabylonTexture ExportTexture(ITexmap texMap, BabylonScene babylonScene, float amount = 1.0f, bool allowCube = false, bool forceAlpha = false)
515574
{
516-
IBitmapTex texture = _getBitmapTex(texMap);
575+
IBitmapTex texture = _getBitmapTex(texMap, false);
576+
if (texture == null)
577+
{
578+
float specialAmount;
579+
var specialTexMap = _getSpecialTexmap(texMap, out specialAmount);
580+
texture = _getBitmapTex(specialTexMap, false);
581+
amount *= specialAmount;
582+
}
583+
517584
if (texture == null)
518585
{
519586
return null;
@@ -811,15 +878,15 @@ private bool _isTextureCube(string filepath)
811878
// --------- Utils ---------
812879
// -------------------------
813880

814-
private IBitmapTex _getBitmapTex(ITexmap texMap)
881+
private IBitmapTex _getBitmapTex(ITexmap texMap, bool raiseError = true)
815882
{
816883
if (texMap == null || texMap.GetParamBlock(0) == null || texMap.GetParamBlock(0).Owner == null)
817884
{
818885
return null;
819886
}
820887

821888
var texture = texMap.GetParamBlock(0).Owner as IBitmapTex;
822-
if (texture == null)
889+
if (texture == null && raiseError)
823890
{
824891
RaiseError($"Texture type is not supported. Use a Bitmap instead.", 2);
825892
}

0 commit comments

Comments
 (0)