|
| 1 | +const |
| 2 | + render = op.inTrigger("render"), |
| 3 | + inArea = op.inValueSelect("Area", ["Sphere", "Box", "Tri Prism", "Hex Prism", "Axis X", "Axis Y", "Axis Z", "Axis X Infinite", "Axis Y Infinite", "Axis Z Infinite"], "Sphere"), |
| 4 | + |
| 5 | + inViz = op.inBool("Visualize Area", false), |
| 6 | + |
| 7 | + inWorldSpace = op.inValueBool("WorldSpace", false), |
| 8 | + x = op.inValue("x"), |
| 9 | + y = op.inValue("y"), |
| 10 | + z = op.inValue("z"), |
| 11 | + |
| 12 | + // inFalloff = op.inFloat("Falloff", 0), |
| 13 | + // inFalloffCurve = op.inSwitch("Falloff Curve", ["Linear", "Smoothstep", "pow2", "pow3"], "Linear"), |
| 14 | + |
| 15 | + inRadius = op.inValue("Radius", 1), |
| 16 | + sizeX = op.inFloat("Area Size X", 1), |
| 17 | + sizeY = op.inFloat("Area Size Y", 1), |
| 18 | + sizeZ = op.inFloat("Area Size Z", 1), |
| 19 | + |
| 20 | + changeTranslateX = op.inFloat("Translate X", 0), |
| 21 | + changeTranslateY = op.inFloat("Translate Y", 0), |
| 22 | + changeTranslateZ = op.inFloat("Translate Z", 0), |
| 23 | + |
| 24 | + changeScaleX = op.inFloat("Scale X", 0.5), |
| 25 | + changeScaleY = op.inFloat("Scale Y", 0.5), |
| 26 | + changeScaleZ = op.inFloat("Scale Z", 0.5), |
| 27 | + |
| 28 | + next = op.outTrigger("trigger"); |
| 29 | + |
| 30 | +const cgl = op.patch.cgl; |
| 31 | + |
| 32 | +op.setPortGroup("Area", [inRadius, sizeX, sizeY, sizeZ]); |
| 33 | + |
| 34 | +inViz.onChange = |
| 35 | + inWorldSpace.onChange = |
| 36 | + // inFalloffCurve.onChange = |
| 37 | + inArea.onChange = updateDefines; |
| 38 | + |
| 39 | +const srcHeadVert = attachments.deformarea_vert; |
| 40 | + |
| 41 | +const srcBodyVert = "" |
| 42 | + .endl() + "pos=MOD_deform(pos,mMatrix,false,norm);" |
| 43 | + .endl() + "norm=MOD_deform(pos,mMatrix,true,norm).xyz;" |
| 44 | + .endl(); |
| 45 | + |
| 46 | +const mod = new CGL.ShaderModifier(cgl, op.name, { "opId": op.id }); |
| 47 | +mod.addModule({ |
| 48 | + "title": op.name, |
| 49 | + "name": "MODULE_VERTEX_POSITION", |
| 50 | + "srcHeadVert": attachments.deformarea_vert, |
| 51 | + "srcBodyVert": srcBodyVert |
| 52 | +}); |
| 53 | + |
| 54 | +mod.addModule({ |
| 55 | + "title": op.name, |
| 56 | + "name": "MODULE_COLOR", |
| 57 | + "srcHeadFrag": "IN float MOD_viz;".endl(), |
| 58 | + // "srcBodyFrag": "col=mix(col,vec4(1.,0.,0.,1.),MOD_viz);" |
| 59 | + "srcBodyFrag": "#ifdef MOD_VIZ\nif(MOD_viz>0.0001)col=vec4(1.,0.,0.,1.);\n#endif\n" |
| 60 | +}); |
| 61 | + |
| 62 | +mod.addUniformVert("f", "MOD_fallOff", 0); |
| 63 | +mod.addUniformVert("f", "MOD_radius", inRadius); |
| 64 | + |
| 65 | +mod.addUniformVert("3f", "MOD_pos", x, y, z); |
| 66 | +mod.addUniformVert("3f", "MOD_scale", sizeX, sizeY, sizeZ); |
| 67 | +mod.addUniformVert("3f", "MOD_changeScale", changeScaleX, changeScaleY, changeScaleZ); |
| 68 | +mod.addUniformVert("3f", "MOD_changeTranslate", changeTranslateX, changeTranslateY, changeTranslateZ); |
| 69 | + |
| 70 | +updateDefines(); |
| 71 | + |
| 72 | +function updateDefines() |
| 73 | +{ |
| 74 | + // mod.toggleDefine("MOD_FALLOFF_SMOOTH", inFalloffCurve.get() == "Smoothstep"); |
| 75 | + // mod.toggleDefine("MOD_FALLOFF_POW2", inFalloffCurve.get() == "pow2"); |
| 76 | + // mod.toggleDefine("MOD_FALLOFF_POW3", inFalloffCurve.get() == "pow3"); |
| 77 | + |
| 78 | + mod.toggleDefine("MOD_AREA_SPHERE", inArea.get() == "Sphere"); |
| 79 | + mod.toggleDefine("MOD_AREA_BOX", inArea.get() == "Box"); |
| 80 | + mod.toggleDefine("MOD_AREA_AXIS_X", inArea.get() == "Axis X"); |
| 81 | + mod.toggleDefine("MOD_AREA_AXIS_Y", inArea.get() == "Axis Y"); |
| 82 | + mod.toggleDefine("MOD_AREA_AXIS_Z", inArea.get() == "Axis Z"); |
| 83 | + mod.toggleDefine("MOD_AREA_AXIS_X_INFINITE", inArea.get() == "Axis X Infinite"); |
| 84 | + mod.toggleDefine("MOD_AREA_AXIS_Y_INFINITE", inArea.get() == "Axis Y Infinite"); |
| 85 | + mod.toggleDefine("MOD_AREA_AXIS_Z_INFINITE", inArea.get() == "Axis Z Infinite"); |
| 86 | + mod.toggleDefine("MOD_AREA_TRIPRISM", inArea.get() == "Tri Prism"); |
| 87 | + mod.toggleDefine("MOD_AREA_HEXPRISM", inArea.get() == "Hex Prism"); |
| 88 | + |
| 89 | + mod.toggleDefine("MOD_WORLDSPACE", inWorldSpace.get()); |
| 90 | + mod.toggleDefine("MOD_VIZ", inViz.get()); |
| 91 | + |
| 92 | + inRadius.setUiAttribs({ "greyout": inArea.get() != "Sphere" }); |
| 93 | + sizeZ.setUiAttribs({ "greyout": inArea.get() != "Box" }); |
| 94 | + sizeY.setUiAttribs({ "greyout": inArea.get() != "Box" }); |
| 95 | + sizeX.setUiAttribs({ "greyout": inArea.get() != "Box" }); |
| 96 | +} |
| 97 | + |
| 98 | +render.onTriggered = function () |
| 99 | +{ |
| 100 | + if (CABLES.UI) |
| 101 | + { |
| 102 | + if (op.isCurrentUiOp()) gui.setTransformGizmo({ "posX": x, "posY": y, "posZ": z }); |
| 103 | + |
| 104 | + if (cgl.shouldDrawHelpers(op)) |
| 105 | + { |
| 106 | + cgl.pushModelMatrix(); |
| 107 | + mat4.translate(cgl.mMatrix, cgl.mMatrix, [x.get(), y.get(), z.get()]); |
| 108 | + |
| 109 | + if (inArea.get() == "Sphere") |
| 110 | + CABLES.GL_MARKER.drawSphere(op, inRadius.get()); |
| 111 | + cgl.popModelMatrix(); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + mod.bind(); |
| 116 | + next.trigger(); |
| 117 | + mod.unbind(); |
| 118 | +}; |
| 119 | + |
| 120 | +/// |
0 commit comments