forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JS Bindings for Essl Shader Generation (#1257)
- Loading branch information
Showing
41 changed files
with
951 additions
and
1,729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
source/JsMaterialX/JsMaterialXGenEssl/JsEsslShaderGenerator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// TM & (c) 2021 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd. | ||
// All rights reserved. See LICENSE.txt for license. | ||
// | ||
|
||
#include <MaterialXGenEssl/EsslShaderGenerator.h> | ||
#include <MaterialXGenShader/Shader.h> | ||
#include <MaterialXGenShader/ShaderStage.h> | ||
#include <MaterialXGenShader/Util.h> | ||
|
||
#include <emscripten/bind.h> | ||
|
||
namespace ems = emscripten; | ||
namespace mx = MaterialX; | ||
|
||
/// Returns the first renderable element from the given document. This element can be used to generate a shader. | ||
mx::ElementPtr findRenderableElement(mx::DocumentPtr doc) | ||
{ | ||
mx::StringVec renderablePaths; | ||
std::vector<mx::TypedElementPtr> elems; | ||
mx::findRenderableElements(doc, elems); | ||
|
||
for (mx::TypedElementPtr elem : elems) | ||
{ | ||
mx::TypedElementPtr renderableElem = elem; | ||
mx::NodePtr node = elem->asA<mx::Node>(); | ||
if (node && node->getType() == mx::MATERIAL_TYPE_STRING) | ||
{ | ||
std::vector<mx::NodePtr> shaderNodes = getShaderNodes(node, mx::SURFACE_SHADER_TYPE_STRING); | ||
if (!shaderNodes.empty()) | ||
{ | ||
renderableElem = *shaderNodes.begin(); | ||
} | ||
} | ||
|
||
const auto& renderablePath = renderableElem->getNamePath(); | ||
mx::ElementPtr renderableElement = doc->getDescendant(renderablePath); | ||
mx::TypedElementPtr typedElem = renderableElement ? renderableElement->asA<mx::TypedElement>() : nullptr; | ||
if (typedElem) | ||
{ | ||
return renderableElement; | ||
} | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
EMSCRIPTEN_BINDINGS(EsslShaderGenerator) | ||
{ | ||
ems::class_<mx::EsslShaderGenerator, ems::base<mx::ShaderGenerator>>("EsslShaderGenerator") | ||
.smart_ptr_constructor("EsslShaderGenerator", &std::make_shared<mx::EsslShaderGenerator>) | ||
; | ||
|
||
ems::function("findRenderableElement", &findRenderableElement); | ||
} |
Oops, something went wrong.