1 /**
2     Deformation Bindings
3 
4     Copyright: 
5         Copyright © 2020-2026, Inochi2D Project
6     
7     License:
8         $(LINK2 https://github.com/Inochi2D/inochi2d/blob/main/LICENSE, BSD 2-clause License)
9 
10     Authors:
11         Luna Nielsen
12         Mireille Arseneault
13         Hoshino Lina
14 */
15 module inochi2d.param.bindings.deform;
16 import inochi2d.param.parameters;
17 import inochi2d.param.bindings;
18 import inochi2d.param.utils;
19 import inochi2d.core.vector2d;
20 import inochi2d.core.registry;
21 import inochi2d.core.serde;
22 import inochi2d.core.math;
23 import inochi2d.core.guid;
24 import inochi2d.common;
25 import inochi2d.puppet;
26 import inochi2d.nodes;
27 import nulib;
28 import numem;
29 
30 ///**
31 //    Parameter binding to a deformation property.
32 //*/
33 //@TypeId("deform", IN_MAKE_TAG!(1, 0))
34 //class ParameterDeformBinding : ParameterNodeBinding {
35 //private:
36 //@nogc:
37 //    vector2d!Deformation values_;
38 
39 //protected:
40 
41 //    /**
42 //        Serialize this parameter binding.
43 //    */
44 //    override
45 //    void onSerialize(ref DataNode object) {
46 //        super.onSerialize(object);
47 
48 //    }
49 
50 //    /**
51 //        Deserialize this parameter.
52 //    */
53 //    override
54 //    void onDeserialize(ref DataNode object, ref ModelState state) {
55 //        super.onDeserialize(object, state);
56 //        if (state.doUpgrade08) {
57 //            if ("values" in object) {
58 //                object["values"].deserialize08NestedArrays(
59 //                    values_, 
60 //                    state,
61 //                    parameter.dimensions == 1 ?
62 //                        vec2u(1, parameter.elementCounts[0]) :
63 //                        vec2u(parameter.elementCounts[0], parameter.elementCounts[1])
64 //                );
65 //            }
66 //            return;
67 //        }
68 
69 //    }
70 
71 //public:
72 
73 //    /**
74 //        The values of the binding.
75 //    */
76 //    @property slice2d!Deformation values() => values_[];
77 
78 //    /**
79 //        Construct a deformation binding without a target.
80 
81 //        Params:
82 //            parameter = The owner/parent of this binding.
83 //    */
84 //    this(Parameter param) {
85 //        super(param);
86 //        values_.resizeToParam(param);
87 //    }
88 
89 //    /**
90 //        Construct a deformation binding.
91 
92 //        Params:
93 //            param   = The owner/parent of this binding.
94 //            node    = The node affected by this binding.
95 //    */
96 //    this(Parameter param, Node node) {
97 //        super(param, node);
98 //        this.values_.resizeToParam(param);
99 //    }
100 
101 //    /**
102 //        Apply the given interpolated keypoint to this binding.
103 
104 //        Params:
105 //            index = The index of the first keypoint in our quartet.
106 //            norm = The normalized position in our keypoint quartet.
107 //    */
108 //    override
109 //    void apply(vec2u index, vec2 norm) {
110 //        apply(getInterpolatedKeypoint(index, norm));
111 //        if (auto deform = cast(IDeformable)target) {
112 //            deform.deform(value.vertexOffsets, false);
113 //        }
114 //    }
115 
116 //    /**
117 //        Fill undefined keypoints with sensible defaults.
118 //    */
119 //    override void fillBlanks() { }
120 
121 //    /**
122 //        Check whether the keypoint at the given index is defined.
123 //    */
124 //    override
125 //    bool isDefined(uint index) const {
126 //        return defined_[0, index];
127 //    }
128 
129 //    /**
130 //        Check whether this binding is compatible with the given node.
131 //    */
132 //    override
133 //    bool isCompatibleWith(Node other) const {
134 //        if (auto a = cast(IDeformable)target) {
135 //            if (auto b = cast(IDeformable)other) {
136 //                return a.deformPoints.length == b.deformPoints.length;
137 //            }
138 //        }
139 
140 //        return false;
141 //    }
142 
143 //    /**
144 //        Reinitialize the keypoint at the given index to its default value.
145 //    */
146 //    override
147 //    void reset(vec2u index) {
148 //        auto deform = cast(IDeformable)target;
149 //        this.values_[index.y, index.x].clear(deform.deformPoints.length);
150 //        this.defined_[index.y, index.x] = true;
151 //    }
152 
153 //    /**
154 //        Initialize the keypoint at the given index with its current value.
155 //    */
156 //    override
157 //    void enable(vec2u index) {
158 //        this.defined_[index.y, index.x] = true;
159 //        fillBlanks();
160 //    }
161 
162 //    /**
163 //        Clear the keypoint at the given index to its default value.
164 //    */
165 //    override
166 //    void disable(vec2u index) {
167 //        this.values_[index.y, index.x] = T.init;
168 //        this.defined_[index.y, index.x] = false;
169 //        fillBlanks();
170 //    }
171 
172 //    // Add general implementation
173 //    mixin ParameterNodeBindingImpl!Deformation;
174 //}
175 //mixin Register!(ParameterDeformBinding, in_binding_registry);