Skip to content

Commit

Permalink
Update gltfMtlx.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
kwokcb committed Sep 29, 2023
1 parent ee8f5fb commit 75e47c3
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions source/MaterialXglTF/gltfMtlx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 68,
"execution_count": 97,
"metadata": {},
"outputs": [
{
Expand All @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 69,
"execution_count": 98,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -704,7 +704,7 @@
},
{
"cell_type": "code",
"execution_count": 72,
"execution_count": 99,
"metadata": {},
"outputs": [
{
Expand All @@ -727,22 +727,27 @@
"\n",
"<?xml version=\"1.0\"?>\n",
"<materialx version=\"1.38\">\n",
" <gltf_pbr name=\"SHD_M_BoomBox\" type=\"surfaceshader\" nodedef=\"ND_gltf_pbr_surfaceshader\" />\n",
" <gltf_pbr name=\"SHD_M_BoomBox\" type=\"surfaceshader\" nodedef=\"ND_gltf_pbr_surfaceshader\">\n",
" <input name=\"base_color\" type=\"color3\" nodename=\"image_basecolor\" output=\"outcolor\" />\n",
" <input name=\"alpha\" type=\"float\" nodename=\"image_basecolor\" output=\"outa\" />\n",
" </gltf_pbr>\n",
" <surfacematerial name=\"MAT_M_BoomBox\" type=\"material\">\n",
" <input name=\"surfaceshader\" type=\"surfaceshader\" nodename=\"SHD_M_BoomBox\" />\n",
" </surfacematerial>\n",
" <gltf_colorImage name=\"image_basecolor\" type=\"multioutput\" nodedef=\"ND_gltf_colorimage\">\n",
" <input name=\"file\" type=\"filename\" value=\"BoomBoxWithAxes_baseColor.png\" />\n",
" <input name=\"file\" type=\"filename\" value=\"BoomBoxWithAxes_baseColor.png\" colorspace=\"srgb_texture\" />\n",
" </gltf_colorImage>\n",
" <gltf_pbr name=\"SHD_M_Coordinates\" type=\"surfaceshader\" nodedef=\"ND_gltf_pbr_surfaceshader\">\n",
" <input name=\"base_color\" type=\"color3\" nodename=\"image_basecolor2\" output=\"outcolor\" />\n",
" <input name=\"alpha\" type=\"float\" nodename=\"image_basecolor2\" output=\"outa\" />\n",
" <input name=\"metallic\" type=\"float\" value=\"0.0\" />\n",
" <input name=\"roughness\" type=\"float\" value=\"0.735\" />\n",
" </gltf_pbr>\n",
" <surfacematerial name=\"MAT_M_Coordinates\" type=\"material\">\n",
" <input name=\"surfaceshader\" type=\"surfaceshader\" nodename=\"SHD_M_Coordinates\" />\n",
" </surfacematerial>\n",
" <gltf_colorImage name=\"image_basecolor2\" type=\"multioutput\" nodedef=\"ND_gltf_colorimage\">\n",
" <input name=\"file\" type=\"filename\" value=\"BoomBoxWithAxes_baseColor1.png\" />\n",
" <input name=\"file\" type=\"filename\" value=\"BoomBoxWithAxes_baseColor1.png\" colorspace=\"srgb_texture\" />\n",
" </gltf_colorImage>\n",
"</materialx>\n",
"\n"
Expand Down Expand Up @@ -802,6 +807,7 @@
" print(' pbrMetallicRoughness: %s' % pbrMetallicRoughness)\n",
"\n",
" # Parse base color\n",
" # Change this to reusable method : readColorInput\n",
" if 'baseColorTexture' in pbrMetallicRoughness:\n",
" baseColorTexture = pbrMetallicRoughness['baseColorTexture']\n",
" baseColorTextureIndex = baseColorTexture['index']\n",
Expand All @@ -821,6 +827,28 @@
" imageNode.setAttribute(mx.InterfaceElement.NODE_DEF_ATTRIBUTE, \"ND_gltf_colorimage\");\n",
" fileInput = imageNode.addInputFromNodeDef(mx.Implementation.FILE_ATTRIBUTE)\n",
" fileInput.setValue(fileName, mx.FILENAME_TYPE_STRING) \n",
" colorspace = 'srgb_texture'\n",
" if len(colorspace):\n",
" colorspaceattr = \"colorspace\" # mx.Element.COLOR_SPACE_ATTRIBUTE missing\n",
" fileInput.setAttribute(colorspaceattr, colorspace)\n",
"\n",
" newTextureName = imageNode.getName()\n",
" colorInputName = \"base_color\"\n",
" colorInput = shaderNode.addInputFromNodeDef(colorInputName)\n",
" #mx.PortElement.NODE_NAME_ATTRIBUTE\n",
" colorInput.setAttribute('nodename', newTextureName);\n",
" colorInput.setOutputString(\"outcolor\");\n",
" #mx.AttributeDef.VALUE_ATTRIBUTE\n",
" colorInput.removeAttribute('value');\n",
"\n",
" alphaInputName = \"alpha\"\n",
" alphaInput = shaderNode.addInputFromNodeDef(alphaInputName)\n",
" #mx.PortElement.NODE_NAME_ATTRIBUTE\n",
" alphaInput.setAttribute('nodename', newTextureName)\n",
" alphaInput.setOutputString(\"outa\")\n",
" #mx.AttributeDef.VALUE_ATTRIBUTE\n",
" alphaInput.removeAttribute('value')\n",
"\n",
"\n",
" # Parse metalic, roughness, and occlusion (if not specified separately)\n",
"\n",
Expand Down

0 comments on commit 75e47c3

Please sign in to comment.