Skip to content

Commit

Permalink
Fixed export of transparent materials
Browse files Browse the repository at this point in the history
  • Loading branch information
ziriax committed Jun 15, 2018
1 parent 951aac1 commit ab18f62
Show file tree
Hide file tree
Showing 7 changed files with 1,192 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ I consider this plugin to be in *beta* stage, use it at your own risk :)
* do not export standard materials (lambert, phong, etc), only GLTF PBR materials.
* by default standard materials are converted
* but just the color and transparency is copied for now.
* `-excludeUnusedTexcoord (-eut)` *(optional)*
* exclude texture coordinates when the mesh primitive doesn't have textures?
* by default texture coordinates are always exported
* `-defaultMaterial (-dm)` *(optional)*
* always generates a glTF PBR material, even if no material is assigned to a mesh in Maya
Expand Down
1,170 changes: 1,170 additions & 0 deletions maya/scenes/TranparentCube1.ma

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions maya/scripts/maya2glTF_UI.mel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
proc string _quoted(string $text)
proc string _quoted(string $text)
{
string $quote = "\"";
return $quote+$text+$quote;
Expand Down Expand Up @@ -251,7 +251,7 @@ global proc maya2glTF_UI()
global string $gMainProgressBar;

// This is auto-updated by msbuild
string $maya2glTF_version = "v0.9.6-beta 49a2d6f";
string $maya2glTF_version = "v0.9.6-beta 951aac1";

if (`window -exists maya2glTF_exporter_window`)
deleteUI maya2glTF_exporter_window;
Expand Down
2 changes: 1 addition & 1 deletion src/ExportableAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void ExportableAsset::save()
const auto outputFolder = path(args.outputFolder.asChar());
create_directories(outputFolder);

const auto outputFilename = std::string(args.sceneName.asChar()) + (args.glb ? ".glb" : ".glTF");
const auto outputFilename = std::string(args.sceneName.asChar()) + (args.glb ? ".glb" : ".gltf");
const auto outputPath = outputFolder / outputFilename;

cout << prefix << "Writing glTF file to '" << outputPath << "'" << endl;
Expand Down
17 changes: 13 additions & 4 deletions src/ExportableMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ bool ExportableMaterial::getScalar(const MObject& obj, const char* attributeName
return DagHelper::getPlugValue(obj, attributeName, scalar);
}

bool ExportableMaterial::getString(const MObject& obj, const char* attributeName, MString& string)
{
return DagHelper::getPlugValue(obj, attributeName, string);
}

bool ExportableMaterial::getColor(const MObject& obj, const char* attributeName, Float4& color)
{
MColor c;
Expand Down Expand Up @@ -177,17 +182,21 @@ void ExportableMaterialPBR::loadPBR(ExportableResources& resources, const MFnDep

Float4 customBaseColor = m_glBaseColorFactor;
float customBaseAlpha = m_glBaseColorFactor[3];
if (getColor(shaderObject, "u_BaseColorFactorRGB", customBaseColor) ||
getScalar(shaderObject, "u_BaseColorFactorA", customBaseAlpha))
MString technique = "solid";

const auto hasCustomColor = getColor(shaderObject, "u_BaseColorFactorRGB", customBaseColor);
const auto hasCustomAlpha = getScalar(shaderObject, "u_BaseColorFactorA", customBaseAlpha);
const auto hasTechnique = getString(shaderObject, "technique", technique);

if (hasCustomColor | hasCustomAlpha)
{
customBaseColor[3] = customBaseAlpha;
m_glBaseColorFactor = customBaseColor;
m_glMetallicRoughness.baseColorFactor = &m_glBaseColorFactor[0];
m_glMaterial.metallicRoughness = &m_glMetallicRoughness;
}

// TODO: Add transparency texture to our shader!
if (m_glBaseColorFactor[3] != 1)
if (hasTechnique && technique.toLowerCase() == "transparent")
{
m_glMaterial.alphaMode = "BLEND";
}
Expand Down
1 change: 1 addition & 0 deletions src/ExportableMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ExportableMaterial

static bool getScalar(const MObject& shaderObject, const char* attributeName, float& scalar);
static bool getColor(const MObject& shaderObject, const char* attributeName, Float4& color);
static bool getString(const MObject& shaderObject, const char* attributeName, MString& string);

private:
DISALLOW_COPY_MOVE_ASSIGN(ExportableMaterial);
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include "externals.h"

const char* version = "v0.9.6-beta 49a2d6f";
const char* version = "v0.9.6-beta 951aac1";

0 comments on commit ab18f62

Please sign in to comment.