1 /**
2     Bridge parameter values to mesh deformations and more.
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.node;
16 import inochi2d.param.parameters;
17 import inochi2d.param.bindings;
18 import inochi2d.param.utils;
19 import inochi2d.core.registry;
20 import inochi2d.core.vector2d;
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 //    A parameter binding affecting a node.
32 //*/
33 //abstract
34 //class ParameterNodeBinding : ParameterBinding {
35 //private:
36 //@nogc:
37 //    GUID nodeId;
38 //    Node target_;
39 
40 //protected:
41 //    vector2d!bool defined_;
42 
43 //    /**
44 //        Serialize this binding.
45 //    */
46 //    override
47 //    void onSerialize(ref DataNode object) {
48 //        super.onSerialize(object);
49 //        object["target"] = target_.guid.toString()[];
50 //        object["defined"] = defined_.data.serialize();
51 //    }
52 
53 //    /**
54 //        Deserialize this binding.
55 //    */
56 //    override
57 //    void onDeserialize(ref DataNode object, ref ModelState state) {
58 //        super.onDeserialize(object, state);
59 //        if (state.doUpgrade08) {
60 //            this.nodeId = object.tryGetGUID(state, "node", "target");
61 //            if ("isSet" in object) {
62 //                object["isSet"].deserialize08NestedArrays(
63 //                    defined_, 
64 //                    state,
65 //                    parameter.dimensions == 1 ?
66 //                        vec2u(1, parameter.elementCounts[0]) :
67 //                        vec2u(parameter.elementCounts[0], parameter.elementCounts[1])
68 //                );
69 //            }
70 //            return;
71 //        }
72 
73 //        this.nodeId = object.tryGetGUID(state, "node", "target");
74 //        object.tryGetRef(state, defined_.data, "defined");
75 //    }
76 
77 //    /**
78 //        Finalizes the parameter binding.
79 
80 //        Params:
81 //            puppet =    The parent puppet
82 //            state =     The state of the deserializer.
83 //    */
84 //    override
85 //    void onFinalize(Puppet puppet, ref ModelState state) {
86 //        if (auto node = puppet.find!Node(nodeId)) {
87 //            this.target_ = node;
88 //        }
89 //    }
90 
91 //public:
92 
93 //    /**
94 //        The target of the binding.
95 //    */
96 //    @property inout(Node) target() inout => target_;
97 //    @property void target(Node value) {
98 //        if (this.target_)
99 //            this.target_.release();
100 
101 //        this.target_ = value.retained;
102 //    }
103 
104 //    /**
105 //        Construct a binding from its parameter.
106 
107 //        Params:
108 //            param = The parameter this binding will belong to.
109 //    */
110 //    this(Parameter param) {
111 //        super(param);
112 //        this.defined_.resizeToParam(param);
113 //    }
114 
115 //    /**
116 //        Construct a binding from its parameter, target node.
117 
118 //        Params:
119 //            param   = The parameter this binding will belong to.
120 //            node    = The node being affected by this binding.
121 //    */
122 //    this(Parameter param, Node node) {
123 //        super(param);
124 //        this.defined_.resizeToParam(param);
125 //        this.target_ = node;
126 //    }
127 //}
128 
129 ///**
130 //    Template that implements core functionality.
131 //*/
132 //mixin template ParameterNodeBindingImpl(T) {
133 
134 //    /**
135 //        Keypoint operation to insert a keypoint at the given position.
136 //    */
137 //    override
138 //    void insertKeypoint(ParameterAxis axis, uint index) {
139 //        final switch (axis) {
140 //            case ParameterAxis.rows:
141 //                this.values_.resize(values_.rows + 1, values_.columns);
142 //                this.defined_.resize(defined_.rows + 1, defined_.columns);
143 //                this.values_[index + 1 .. $, 0 .. $] = values_[index .. $ - 1, 0 .. $];
144 //                this.defined_[index + 1 .. $, 0 .. $] = defined_[index .. $ - 1, 0 .. $];
145 //                this.values_[index, 0 .. $] = T.init;
146 //                this.defined_[index, 0 .. $] = false;
147 //                break;
148 
149 //            case ParameterAxis.columns:
150 //                this.values_.resize(values_.rows, values_.columns + 1);
151 //                this.defined_.resize(defined_.rows, defined_.columns + 1);
152 //                this.values_[0 .. $, index + 1 .. $] = values_[0 .. $, index .. $ - 1];
153 //                this.defined_[0 .. $, index + 1 .. $] = defined_[0 .. $, index .. $ - 1];
154 //                this.values_[0 .. $, index] = T.init;
155 //                this.defined_[0 .. $, index] = false;
156 //                break;
157 //        }
158 
159 //        fillBlanks();
160 //    }
161 
162 //    /**
163 //        Keypoint operation to move a keypoint to the given position.
164 //    */
165 //    override
166 //    void moveKeypoint(ParameterAxis axis, uint index, uint dest) {
167 //        assert(false, "not implemented");
168 
169 //        final switch (axis) {
170 //            case ParameterAxis.rows:
171 //                break;
172 
173 //            case ParameterAxis.columns:
174 //                break;
175 //        }
176 
177 //        fillBlanks();
178 //    }
179 
180 //    /**
181 //        Keypoint operation to delete the keypoint at the given position.
182 //    */
183 //    override
184 //    void deleteKeypoint(ParameterAxis axis, uint index) {
185 //        assert(false, "not implemented");
186 
187 //        final switch (axis) {
188 //            case ParameterAxis.rows:
189 //                break;
190 
191 //            case ParameterAxis.columns:
192 //                break;
193 //        }
194 
195 //        fillBlanks();
196 //    }
197 
198 //    /**
199 //        Keypoint operation to scale a keypoint by a given factor.
200 //    */
201 //    override
202 //    void scaleKeypoint(ParameterAxis axis, uint index, float scale) {
203 //        assert(false, "not implemented");
204 //    }
205 
206 //    /**
207 //        Keypoint operation to copy its value to another binding's keypoint.
208 //    */
209 //    override
210 //    void copyKeypoint(vec2u index, ParameterBinding other, vec2u dest) {
211 //        assert(false, "not implemented");
212 //    }
213 
214 //    /**
215 //        Clear all keypoint values.
216 //    */
217 //    override
218 //    void clear() {
219 //        this.defined_[] = false;
220 //        for (uint y = 0; y < values.rows; ++y) {
221 //            for (uint x = 0; x < values.columns; ++x) {
222 //                this.reset(vec2u(y, x));
223 //            }
224 //        }
225 //    }
226 //}