diff --git a/projects/FBX/MayaCamera.cpp b/projects/FBX/MayaCamera.cpp index 1d7e74ad62..1257676f3c 100644 --- a/projects/FBX/MayaCamera.cpp +++ b/projects/FBX/MayaCamera.cpp @@ -514,6 +514,63 @@ ZENO_DEFNODE(LightNode)({ {"shader"}, }); +struct DirtyTBN : INode { + virtual void apply() override { + + auto AxisT = get_input2("T"); + auto AxisB = get_input2("B"); + //auto AxisN = get_input2("N"); + + if (lengthSquared(AxisT) == 0 ) { + AxisT = {1,0,0}; + } + AxisT = zeno::normalize(AxisT); + + if (lengthSquared(AxisB) == 0 ) { + AxisB = {0,0,1}; + } + AxisB = zeno::normalize(AxisB); + + auto tmp = zeno::dot(AxisT, AxisB); + if (abs(tmp) > 0.0) { // not vertical + AxisB -= AxisT * tmp; + AxisB = zeno::normalize(AxisB); + } + + if (has_input("prim")) { + auto prim = get_input("prim"); + + auto pos = prim->userData().get2("pos", {0,0,0}); + auto scale = prim->userData().get2("scale", {1,1,1}); + + auto v0 = pos - AxisT * scale[0] * 0.5f - AxisB * scale[2] * 0.5f; + auto e1 = AxisT * scale[0]; + auto e2 = AxisB * scale[2]; + + prim->verts[0] = v0 + e1 + e2; + prim->verts[1] = v0 + e1; + prim->verts[2] = v0 + e2; + prim->verts[3] = v0; + + set_output("prim", std::move(prim)); + } + } +}; + + +ZENO_DEFNODE(DirtyTBN)({ + { + {"PrimitiveObject", "prim"}, + {"vec3f", "T", "1, 0, 0"}, + {"vec3f", "B", "0, 0, 1"}, + }, + { + "prim" + }, + {}, + {"shader"}, +}); + struct LiveMeshNode : INode { typedef std::vector> UVS; typedef std::vector> VERTICES; diff --git a/zenovis/src/optx/RenderEngineOptx.cpp b/zenovis/src/optx/RenderEngineOptx.cpp index f15530d18f..8558475c36 100644 --- a/zenovis/src/optx/RenderEngineOptx.cpp +++ b/zenovis/src/optx/RenderEngineOptx.cpp @@ -622,7 +622,9 @@ struct GraphicsManager { e2 = -e2; // invert e2 // facing down in local space - nor = zeno::normalize(zeno::cross(e2, e1)); + auto ne2 = zeno::normalize(e2); + auto ne1 = zeno::normalize(e1); + nor = zeno::normalize(zeno::cross(ne2, ne1)); if (ivD) { nor *= -1; } if (prim_in->verts.has_attr("clr")) {