Skip to content

Commit

Permalink
Add the missing requested export flags support #537 (#668)
Browse files Browse the repository at this point in the history
* Update layout definition system

* Fix log window size

* Update auto generated layout system

* Fix log window size in exporter form

* Export Babylon attributes for standard material (backfaceCulling, maxSimultaneousLights, unlit)
Add connection to log prints

* Add default babylon attributes automatically at runtime
Add KHR_materials_unlit checkbox

* Fix Transparency mode when exporting a standard material to glTF
Fix base color and metallic roughness textures names when exporting a standard material to glTF

* Add a babylon material node to hold all attributes
Fix diffuse and alpha textures merging when alpha is read from RGB

* Ignore babylon transparency mode value when exporting
Add Node editor (NE) templates
Update Attribute editor (AE) templates

* Export _unlit attribute for PBRMetallicRoughnessMaterial
Export alphaCutOff attribute for Masked StingrayPBS material only
Export merged color texture for Masked StingrayPBS material
Fix default color initialisation when merging textures

* Add sample files

* Move log feature to dedicated internal class
Add log level

* Fix transparencyMode and alpha for Standard and Arnold materials

* Add babylon material attributes to native materials
Export babylon material attributes

* Get arnold material opacity from dedicated attributes

* Add samples for babylon material attributes attached to native materials

* Set an unique ID for babylon attributes of an Arnold material

* //Add the user custom attributes to metadata

* // add custom user attributes in babylon and gltf for the lights, cameras, mesh and materials

* Export custom attributes from nodes and materials

* Do not export null CustomAttributes

* Add samples for custom attributes

* Export custom attributes for instances

* Add support for DoubleSided material

* Fix custom attributes retreivable

* Add alphaCutoff default value for masked materials
Fix diffuse texture bitmap loading in gltf for a standard masked material
Do not export empty metadata array for materials

* //add samples

* Add sample files for DoubleSided material
Fix nb of vertices for back face vertices

* Add alphaCutoff default value for masked materials
Fix nullable metadata cloning

* Update samples for MASK transparency mode

* Format file

* Add automatically babylon attributes to a material when created

* Export custom attributes as extras for lights in glTF
Update sample files and rename objects

* //Add the double sided export in maya
//secured the retrieval of the babylon materials

* Export lights as metadata

* Update samples

* //Fix empty extras

* Clean up

* //Upload and refresh of all the exemples

* Fix opacity color and texture retreival from Arnold material
Fix Standard material conversion when Owner is null
Add safety checks

* Update node and material names in samples

* //Add the parameters to the babylonNode shaderGraph when add manually

* Installer : Add AETemplates and NETemplates for Maya installation

* Update Installer version to 1.3.0
  • Loading branch information
noalak authored and Drigax committed Nov 27, 2019
1 parent d8dfd95 commit 964012a
Show file tree
Hide file tree
Showing 210 changed files with 25,291 additions and 3,600 deletions.
6 changes: 6 additions & 0 deletions 3ds Max/Max2Babylon/2015/Max2Babylon2015.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
<Compile Include="..\Exporter\BabylonExporter.Camera.cs">
<Link>Exporter\BabylonExporter.Camera.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.CustomAttributes.cs">
<Link>Exporter\BabylonExporter.CustomAttributes.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.cs">
<Link>Exporter\BabylonExporter.cs</Link>
</Compile>
Expand All @@ -166,6 +169,9 @@
<Compile Include="..\Exporter\BabylonExporter.Light.cs">
<Link>Exporter\BabylonExporter.Light.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Logger.cs">
<Link>Exporter\BabylonExporter.Logger.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Material.cs">
<Link>Exporter\BabylonExporter.Material.cs</Link>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions 3ds Max/Max2Babylon/2017/Max2Babylon2017.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
<Compile Include="..\Exporter\BabylonExporter.Camera.cs">
<Link>Exporter\BabylonExporter.Camera.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.CustomAttributes.cs">
<Link>Exporter\BabylonExporter.CustomAttributes.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.cs">
<Link>Exporter\BabylonExporter.cs</Link>
</Compile>
Expand All @@ -167,6 +170,9 @@
<Compile Include="..\Exporter\BabylonExporter.Light.cs">
<Link>Exporter\BabylonExporter.Light.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Logger.cs">
<Link>Exporter\BabylonExporter.Logger.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Material.cs">
<Link>Exporter\BabylonExporter.Material.cs</Link>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions 3ds Max/Max2Babylon/2018/Max2Babylon2018.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
<Compile Include="..\Exporter\BabylonExporter.Camera.cs">
<Link>Exporter\BabylonExporter.Camera.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.CustomAttributes.cs">
<Link>Exporter\BabylonExporter.CustomAttributes.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.cs">
<Link>Exporter\BabylonExporter.cs</Link>
</Compile>
Expand All @@ -166,6 +169,9 @@
<Compile Include="..\Exporter\BabylonExporter.Light.cs">
<Link>Exporter\BabylonExporter.Light.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Logger.cs">
<Link>Exporter\BabylonExporter.Logger.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Material.cs">
<Link>Exporter\BabylonExporter.Material.cs</Link>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions 3ds Max/Max2Babylon/2019/Max2Babylon2019.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
<Compile Include="..\Exporter\BabylonExporter.Camera.cs">
<Link>Exporter\BabylonExporter.Camera.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.CustomAttributes.cs">
<Link>Exporter\BabylonExporter.CustomAttributes.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.cs">
<Link>Exporter\BabylonExporter.cs</Link>
</Compile>
Expand All @@ -170,6 +173,9 @@
<Compile Include="..\Exporter\BabylonExporter.Light.cs">
<Link>Exporter\BabylonExporter.Light.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Logger.cs">
<Link>Exporter\BabylonExporter.Logger.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Material.cs">
<Link>Exporter\BabylonExporter.Material.cs</Link>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions 3ds Max/Max2Babylon/2020/Max2Babylon2020.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
<Compile Include="..\Exporter\BabylonExporter.Camera.cs">
<Link>Exporter\BabylonExporter.Camera.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.CustomAttributes.cs">
<Link>Exporter\BabylonExporter.CustomAttributes.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.cs">
<Link>Exporter\BabylonExporter.cs</Link>
</Compile>
Expand All @@ -170,6 +173,9 @@
<Compile Include="..\Exporter\BabylonExporter.Light.cs">
<Link>Exporter\BabylonExporter.Light.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Logger.cs">
<Link>Exporter\BabylonExporter.Logger.cs</Link>
</Compile>
<Compile Include="..\Exporter\BabylonExporter.Material.cs">
<Link>Exporter\BabylonExporter.Material.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ private BabylonCamera ExportCamera(IIGameScene scene, IIGameNode cameraNode, Bab
babylonCamera.parentId = cameraNode.NodeParent.MaxNode.GetGuid().ToString();
}

// Export the custom attributes of this camera
babylonCamera.metadata = ExportExtraAttributes(cameraNode, babylonScene);

babylonCamera.fov = Tools.ConvertFov(maxCamera.GetFOV(0, Tools.Forever));

if (maxCamera.ManualClip == 1)
Expand Down
173 changes: 173 additions & 0 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.CustomAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using Autodesk.Max;
using BabylonExport.Entities;
using System;
using System.Collections.Generic;

namespace Max2Babylon
{
partial class BabylonExporter
{
/// <summary>
/// Return the custom attributes of a material
/// </summary>
/// <param name="materialNode"></param>
/// <param name="babylonScene"></param>
/// <param name="excludeAttributes">Attribute names to not export</param>
public Dictionary<string, object> ExportExtraAttributes(IIGameMaterial gameMaterial, BabylonScene babylonScene, List<string> excludeAttributes = null)
{
// Retreive the max object
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand("obj = sceneMaterials[\"" + gameMaterial.MaterialName + "\"];");

return _ExportExtraAttributes(gameMaterial.IPropertyContainer, babylonScene, excludeAttributes);
}

/// <summary>
/// Return the custom attributes of a material
/// </summary>
/// <param name="materialNode"></param>
/// <param name="babylonScene"></param>
/// <param name="excludeAttributes">Attribute names to not export</param>
public Dictionary<string, object> ExportExtraAttributes(IIGameNode gameNode, BabylonScene babylonScene, List<string> excludeAttributes = null)
{
// Retreive the max object
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand("obj = execute(\"$'" + gameNode.Name + "'\");");

return _ExportExtraAttributes(gameNode.IGameObject.IPropertyContainer, babylonScene, excludeAttributes);
}

/// <summary>
/// Return custom attributes retreive from a max object named "obj"
/// </summary>
/// <param name="metadata"></param>
/// <param name="propertyContainer"></param>
/// <param name="babylonScene"></param>
/// <param name="excludeAttributes">Attribute names to not export</param>
private Dictionary<string, object> _ExportExtraAttributes(IIPropertyContainer propertyContainer, BabylonScene babylonScene, List<string> excludeAttributes = null)
{
RaiseMessage("ExportExtraAttributes", 2);

// Return a string encoded with 2 separators
// Parameter separator: _$€PParam_
// Name/Type separator: _$€PType_
string cmd = "s = \"\""
+ "\r\n" + "for objDef in (custAttributes.getDefs obj) do"
+ "\r\n" + "("
+ "\r\n" + "pbArray = custAttributes.getPBlockDefs objdef"
+ "\r\n" + "for indexPBlock = 1 to pbArray.count do"
+ "\r\n" + "("
+ "\r\n" + "itms = pbArray[indexPBlock]"
+ "\r\n" + "for y = 5 to itms.Count do"
+ "\r\n" + "("
+ "\r\n" + "s = s + \"_$€PParam_\" + itms[y][1]"
+ "\r\n" + "for z = 1 to itms[y][2].Count by 2 do"
+ "\r\n" + "("
+ "\r\n" + "key = itms[y][2][z] as string"
+ "\r\n" + "if (findString key \"type\") != undefined then"
+ "\r\n" + "("
+ "\r\n" + "s = s + \"_$€PType_\" + itms[y][2][z+1]"
+ "\r\n" + ")"
+ "\r\n" + ")"
+ "\r\n" + ")"
+ "\r\n" + ")"
+ "\r\n" + ")"
+ "\r\n" + "s";
string result = ManagedServices.MaxscriptSDK.ExecuteStringMaxscriptQuery(cmd);

if (result == null || result == "")
{
return null;
}

// Parse the result into a dictionary
string[] parameters = result.Split(new string[] { "_$€PParam_" }, StringSplitOptions.RemoveEmptyEntries);
Dictionary<string, string> customAttributesTypeByName = new Dictionary<string, string>();
foreach (string parameter in parameters)
{
string[] customAttribute = parameter.Split(new string[] { "_$€PType_" }, StringSplitOptions.RemoveEmptyEntries);
string key = customAttribute[0];
if (customAttributesTypeByName.ContainsKey(key) == false)
{
customAttributesTypeByName.Add(key, customAttribute[1]);
}
}

// Remove preset custom attributes
customAttributesTypeByName.Remove("presetName_str");
customAttributesTypeByName.Remove("preset_str");
customAttributesTypeByName.Remove("rampOn");

// Remove specified attributes
if (excludeAttributes != null)
{
foreach (string excludeAttribute in excludeAttributes)
{
customAttributesTypeByName.Remove(excludeAttribute);
}
}

// Handle each attribute type
Dictionary<string, object> metadata = new Dictionary<string, object>();
foreach (KeyValuePair<string, string> entry in customAttributesTypeByName)
{
object obj = null;

RaiseMessage(entry.Key + "=" + entry.Value, 2);

switch (entry.Value.ToLowerInvariant())
{
case "float":
case "angle": // in rad units
case "worldunits":
obj = propertyContainer.GetFloatProperty(entry.Key);
break;
case "percent": // in base 1 (80% => 0.8)
obj = propertyContainer.GetFloatProperty(entry.Key) / 100f;
break;
case "boolean":
obj = propertyContainer.GetBoolProperty(entry.Key);
break;
case "integer":
case "array": // selected enum value expressed as int starting from 1
obj = propertyContainer.GetIntProperty(entry.Key);
break;
case "string":
obj = propertyContainer.GetStringProperty(entry.Key);
break;
case "color": // Color RGB in base 1 (not 255)
obj = propertyContainer.GetPoint3Property(entry.Key).ToArray();
break;
case "frgba": // Color RGBA in base 1 (not 255)
obj = propertyContainer.GetPoint4Property(entry.Key).ToArray();
break;
case "texturemap":
IIGameProperty gameProperty = propertyContainer.QueryProperty(entry.Key);
ITexmap texmap = gameProperty.MaxParamBlock2.GetTexmap(gameProperty.ParamID, 0, 0);
obj = ExportTexture(texmap, babylonScene);
break;
case "node":
// Currently not exported
break;
case "material":
// Currently not exported
break;
default:
RaiseWarning("Unknown type '" + entry.Value + "' for custom attribute named '" + entry.Key + "'", 2);
break;
}

if (obj != null)
{
metadata.Add(entry.Key, obj);
}
}

// Print all extra attributes
foreach (KeyValuePair<string, object> entry in metadata)
{
RaiseVerbose(entry.Key + "=" + entry.Value, 2);
}

return metadata;
}
}
}
3 changes: 3 additions & 0 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ private BabylonNode ExportLight(IIGameScene scene, IIGameNode lightNode, Babylon
RaiseMessage(lightNode.Name, 1);
babylonLight.name = lightNode.Name;

// Export the custom attributes of this light
babylonLight.metadata = ExportExtraAttributes(lightNode, babylonScene);

// If the light has a children and the export is to babylon, add a dummy
// To preserve the position/rotation and the hierarchy, we create a dummy that will contains as direct children the light and the light children
// The light will have no children. The dummy will contains the position and rotation animations.
Expand Down
Loading

0 comments on commit 964012a

Please sign in to comment.