ShaderGraph.hx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package hrt.prefab;
  2. class ShaderGraph extends DynamicShader {
  3. public function new(?parent) {
  4. super(parent);
  5. type = "shadergraph";
  6. }
  7. override public function loadShaderDef(ctx: Context) {
  8. if(shaderDef == null) {
  9. var shaderGraph = new hrt.shgraph.ShaderGraph(source);
  10. shaderDef = shaderGraph.compile();
  11. }
  12. if(shaderDef == null)
  13. return;
  14. #if editor
  15. for( v in shaderDef.inits ) {
  16. if(!Reflect.hasField(props, v.variable.name)) {
  17. Reflect.setField(props, v.variable.name, v.value);
  18. }
  19. }
  20. #end
  21. }
  22. #if editor
  23. override function getHideProps() : HideProps {
  24. return { icon : "scribd", name : "Shader Graph", fileSource : ["shgraph"], allowParent : function(p) return p.to(Object2D) != null || p.to(Object3D) != null };
  25. }
  26. override function edit( ctx : EditContext ) {
  27. super.edit(ctx);
  28. var btn = new hide.Element("<input type='submit' style='width: 100%; margin-top: 10px;' value='Open Shader Graph' />");
  29. btn.on("click", function() {
  30. ctx.ide.openFile(source);
  31. });
  32. ctx.properties.add(btn,this.props, function(pname) {
  33. ctx.onChange(this, pname);
  34. });
  35. }
  36. #end
  37. static var _ = Library.register("shgraph", ShaderGraph);
  38. }