{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreidpzmsbnns5srmj4r7bbhksqzxffo2qqbruxhfkh4ghy3w2iejdne",
    "uri": "at://did:plc:dxjzgxe7cvirxkwfjr2tjspt/app.bsky.feed.post/3mk3hwlv3inl2"
  },
  "path": "/t/lemur-shaderbackgroundcomponent/49571#post_1",
  "publishedAt": "2026-04-22T09:21:41.000Z",
  "site": "https://hub.jmonkeyengine.org",
  "tags": [
    "@Override"
  ],
  "textContent": "\n    package GUI;\n\n    import com.jme3.material.Material;\n    import com.jme3.math.Vector3f;\n    import com.jme3.scene.Geometry;\n    import com.jme3.scene.shape.Quad;\n    import com.simsilica.lemur.core.GuiControl;\n    import com.simsilica.lemur.component.AbstractGuiComponent;\n\n    // 1. 显式实现 Cloneable 接口\n    public class ShaderBackgroundComponent extends AbstractGuiComponent implements Cloneable {\n        private Geometry background;\n        private Material material;\n\n        public ShaderBackgroundComponent(Material material) {\n            this.material = material;\n        }\n\n        @Override\n        public void calculatePreferredSize(Vector3f size) {\n        }\n\n        @Override\n        public void reshape(Vector3f pos, Vector3f size) {\n            if (background == null) {\n                Quad q = new Quad(size.x, size.y);\n                background = new Geometry(\"shader_background\", q);\n                background.setMaterial(material);\n                getNode().attachChild(background);\n            } else {\n                Quad q = (Quad) background.getMesh();\n                if (size.x != q.getWidth() || size.y != q.getHeight()) {\n                    q.updateGeometry(size.x, size.y);\n                    q.clearCollisionData();\n                }\n            }\n\n            background.setLocalTranslation(pos.x, pos.y - size.y, pos.z);\n        }\n\n        @Override\n        public void detach(GuiControl parent) {\n            if (background != null) {\n                getNode().detachChild(background);\n            }\n            super.detach(parent);\n        }\n\n        // ==========================================\n        // 2. 新增重写 clone 方法\n        // ==========================================\n        @Override\n        public ShaderBackgroundComponent clone() {\n            ShaderBackgroundComponent result = (ShaderBackgroundComponent) super.clone();\n\n            result.background = null;\n\n\n            if (this.material != null) {\n                result.material = this.material.clone();\n            }\n\n            return result;\n        }\n    }\n\n\nI use this class to apply some shader effects to the UI.\nI’m not sure if this is the correct way to use it.\n\n\n\n\nBut the result is good, it basically meets my needs.",
  "title": "(Lemur)ShaderBackgroundComponent"
}