@framefields/node-mesh-warp 0.0.0-stage → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +21 -0
- package/CHANGELOG.md +25 -0
- package/LICENCE +202 -0
- package/dist/index.d.mts +56 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +43 -0
- package/dist/index.mjs.map +1 -0
- package/dist/renderer.d.mts +7 -0
- package/dist/renderer.d.mts.map +1 -0
- package/dist/renderer.mjs +3 -0
- package/dist/renderers-DzkHlv-9.mjs +292 -0
- package/dist/renderers-DzkHlv-9.mjs.map +1 -0
- package/package.json +43 -3
- package/src/index.ts +2 -0
- package/src/renderers/index.ts +6 -0
- package/src/renderers/webgpu-renderer.ts +321 -0
- package/src/shared/config.ts +65 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/utils.ts +74 -0
- package/tsconfig.json +13 -0
- package/tsdown.config.ts +13 -0
- package/README.md +0 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
> @framefields/node-mesh-warp@2.0.3 build /Users/okanaslankan/frameshop/nodes/node-mesh-warp
|
|
3
|
+
> tsdown
|
|
4
|
+
|
|
5
|
+
[34mℹ[39m tsdown [2mv0.19.0[22m powered by rolldown [2mv1.0.0-beta.59[22m
|
|
6
|
+
[34mℹ[39m config file: [4m/Users/okanaslankan/frameshop/nodes/node-mesh-warp/tsdown.config.ts[24m
|
|
7
|
+
[34mℹ[39m entry: [34msrc/index.ts, src/renderers/index.ts[39m
|
|
8
|
+
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
|
+
[34mℹ[39m Build start
|
|
10
|
+
[34mℹ[39m Cleaning 9 files
|
|
11
|
+
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m 1.69 kB[22m [2m│ gzip: 0.75 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[1mrenderer.mjs[22m [2m 0.11 kB[22m [2m│ gzip: 0.09 kB[22m
|
|
13
|
+
[34mℹ[39m [2mdist/[22mrenderers-DzkHlv-9.mjs.map [2m15.37 kB[22m [2m│ gzip: 4.65 kB[22m
|
|
14
|
+
[34mℹ[39m [2mdist/[22mrenderers-DzkHlv-9.mjs [2m 8.76 kB[22m [2m│ gzip: 2.90 kB[22m
|
|
15
|
+
[34mℹ[39m [2mdist/[22mindex.mjs.map [2m 3.03 kB[22m [2m│ gzip: 1.11 kB[22m
|
|
16
|
+
[34mℹ[39m [2mdist/[22mindex.d.mts.map [2m 0.55 kB[22m [2m│ gzip: 0.31 kB[22m
|
|
17
|
+
[34mℹ[39m [2mdist/[22mrenderer.d.mts.map [2m 0.12 kB[22m [2m│ gzip: 0.11 kB[22m
|
|
18
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m 2.16 kB[22m [2m│ gzip: 0.68 kB[22m
|
|
19
|
+
[34mℹ[39m [2mdist/[22m[32m[1mrenderer.d.mts[22m[39m [2m 0.29 kB[22m [2m│ gzip: 0.20 kB[22m
|
|
20
|
+
[34mℹ[39m 9 files, total: 32.08 kB
|
|
21
|
+
[32m✔[39m Build complete in [32m6092ms[39m
|
package/CHANGELOG.md
ADDED
package/LICENCE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Gatewai Studio
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import "./renderer.mjs";
|
|
2
|
+
import * as _framefields_core0 from "@framefields/core";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/shared/config.d.ts
|
|
6
|
+
declare const MeshWarpNodeConfigSchema: z.ZodObject<{
|
|
7
|
+
cols: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
rows: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
10
|
+
x: z.ZodNumber;
|
|
11
|
+
y: z.ZodNumber;
|
|
12
|
+
}, z.core.$strip>>>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
type MeshWarpNodeConfig = z.infer<typeof MeshWarpNodeConfigSchema>;
|
|
15
|
+
declare const MeshWarpOperationSchema: z.ZodObject<{
|
|
16
|
+
cols: z.ZodDefault<z.ZodNumber>;
|
|
17
|
+
rows: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
points: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
19
|
+
x: z.ZodNumber;
|
|
20
|
+
y: z.ZodNumber;
|
|
21
|
+
}, z.core.$strip>>>;
|
|
22
|
+
op: z.ZodLiteral<"MeshWarp">;
|
|
23
|
+
metadata: z.ZodOptional<z.ZodAny>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
type MeshWarpOperation = z.infer<typeof MeshWarpOperationSchema>;
|
|
26
|
+
declare const MeshWarpResultSchema: z.ZodObject<{
|
|
27
|
+
selectedOutputIndex: z.ZodLiteral<0>;
|
|
28
|
+
outputs: z.ZodTuple<[z.ZodObject<{
|
|
29
|
+
items: z.ZodTuple<[z.ZodType<_framefields_core0.OutputItem<"Image" | "Video" | "SVG" | "GIF">, unknown, z.core.$ZodTypeInternals<_framefields_core0.OutputItem<"Image" | "Video" | "SVG" | "GIF">, unknown>>], null>;
|
|
30
|
+
}, z.core.$strip>], null>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
type MeshWarpResult = z.infer<typeof MeshWarpResultSchema>;
|
|
33
|
+
declare const WARP_OUTPUT_TYPE_MAP: Record<string, "Image" | "Video" | "GIF" | "SVG">;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/shared/utils.d.ts
|
|
36
|
+
declare function createUniformGrid(cols: number, rows: number): {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
}[];
|
|
40
|
+
declare function interpolateGridPoint(u: number, v: number, oldPoints: {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
}[], oldCols: number, oldRows: number): {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
};
|
|
47
|
+
declare function resizeGrid(oldPoints: {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
}[] | undefined | null, oldCols: number, oldRows: number, newCols: number, newRows: number): {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
}[];
|
|
54
|
+
//#endregion
|
|
55
|
+
export { MeshWarpNodeConfig, MeshWarpNodeConfigSchema, MeshWarpOperation, MeshWarpOperationSchema, MeshWarpResult, MeshWarpResultSchema, WARP_OUTPUT_TYPE_MAP, createUniformGrid, interpolateGridPoint, resizeGrid };
|
|
56
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/shared/config.ts","../src/shared/utils.ts"],"sourcesContent":[],"mappings":";;;;;cAOa,0BAAwB,CAAA,CAAA;;;;IAAxB,CAAA,aAAA;;;;KA4BD,kBAAA,GAAqB,CAAA,CAAE,aAAa;cAEnC,yBAAuB,CAAA,CAAA;;;;;;;EA9BC,EAAA,cAAA,CAAA,UAAA,CAAA;EAAA,QAAA,eAAA,SAAA,CAAA;AA4BrC,CAAA,gBAAY,CAAA;AAEC,KAKD,iBAAA,GAAoB,CAAA,CAAE,KAFhC,CAAA,OAE6C,uBAF7C,CAAA;cAIW,sBAAoB,CAAA,CAAA;;;;;;KASrB,cAAA,GAAiB,CAAA,CAAE,aAAa;cAE/B,sBAAsB;;;iBCvDnB,iBAAA;;;;iBAYA,oBAAA;EDLH,CAAA,EAAA,MAAA;;;;;;iBC+CG,UAAA;;;;;;CD/CqB,EAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { i as resizeGrid, n as createUniformGrid, r as interpolateGridPoint } from "./renderers-DzkHlv-9.mjs";
|
|
2
|
+
import { SingleOutputGenericSchema, VirtualMediaDataSchema, createOutputItemSchema } from "@framefields/core";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/shared/config.ts
|
|
6
|
+
const MeshWarpNodeConfigSchema = z.object({
|
|
7
|
+
cols: z.number().int().min(2).max(12).default(3),
|
|
8
|
+
rows: z.number().int().min(2).max(12).default(3),
|
|
9
|
+
points: z.array(z.object({
|
|
10
|
+
x: z.number().min(0).max(100),
|
|
11
|
+
y: z.number().min(0).max(100)
|
|
12
|
+
})).max(144).optional()
|
|
13
|
+
}).strict().superRefine((data, ctx) => {
|
|
14
|
+
if (data.points && data.points.length > 0) {
|
|
15
|
+
const expected = data.cols * data.rows;
|
|
16
|
+
if (data.points.length !== expected) ctx.addIssue({
|
|
17
|
+
code: z.ZodIssueCode.custom,
|
|
18
|
+
path: ["points"],
|
|
19
|
+
message: `points array must have exactly ${expected} coordinates (cols * rows), got ${data.points.length}`
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const MeshWarpOperationSchema = MeshWarpNodeConfigSchema.extend({
|
|
24
|
+
op: z.literal("MeshWarp"),
|
|
25
|
+
metadata: z.any().optional()
|
|
26
|
+
});
|
|
27
|
+
const MeshWarpResultSchema = SingleOutputGenericSchema(z.union([
|
|
28
|
+
createOutputItemSchema(z.literal("Video"), VirtualMediaDataSchema),
|
|
29
|
+
createOutputItemSchema(z.literal("Image"), VirtualMediaDataSchema),
|
|
30
|
+
createOutputItemSchema(z.literal("SVG"), VirtualMediaDataSchema),
|
|
31
|
+
createOutputItemSchema(z.literal("GIF"), VirtualMediaDataSchema)
|
|
32
|
+
]));
|
|
33
|
+
const WARP_OUTPUT_TYPE_MAP = {
|
|
34
|
+
Video: "Video",
|
|
35
|
+
Lottie: "Video",
|
|
36
|
+
GIF: "GIF",
|
|
37
|
+
Image: "Image",
|
|
38
|
+
SVG: "Image"
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { MeshWarpNodeConfigSchema, MeshWarpOperationSchema, MeshWarpResultSchema, WARP_OUTPUT_TYPE_MAP, createUniformGrid, interpolateGridPoint, resizeGrid };
|
|
43
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/shared/config.ts"],"sourcesContent":["import {\n\tcreateOutputItemSchema,\n\tSingleOutputGenericSchema,\n\tVirtualMediaDataSchema,\n} from \"@framefields/core\";\nimport { z } from \"zod\";\n\nexport const MeshWarpNodeConfigSchema = z\n\t.object({\n\t\tcols: z.number().int().min(2).max(12).default(3),\n\t\trows: z.number().int().min(2).max(12).default(3),\n\t\tpoints: z\n\t\t\t.array(\n\t\t\t\tz.object({\n\t\t\t\t\tx: z.number().min(0).max(100),\n\t\t\t\t\ty: z.number().min(0).max(100),\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.max(144)\n\t\t\t.optional(),\n\t})\n\t.strict()\n\t.superRefine((data, ctx) => {\n\t\tif (data.points && data.points.length > 0) {\n\t\t\tconst expected = data.cols * data.rows;\n\t\t\tif (data.points.length !== expected) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tpath: [\"points\"],\n\t\t\t\t\tmessage: `points array must have exactly ${expected} coordinates (cols * rows), got ${data.points.length}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\nexport type MeshWarpNodeConfig = z.infer<typeof MeshWarpNodeConfigSchema>;\n\nexport const MeshWarpOperationSchema = MeshWarpNodeConfigSchema.extend({\n\top: z.literal(\"MeshWarp\"),\n\tmetadata: z.any().optional(),\n});\n\nexport type MeshWarpOperation = z.infer<typeof MeshWarpOperationSchema>;\n\nexport const MeshWarpResultSchema = SingleOutputGenericSchema(\n\tz.union([\n\t\tcreateOutputItemSchema(z.literal(\"Video\"), VirtualMediaDataSchema),\n\t\tcreateOutputItemSchema(z.literal(\"Image\"), VirtualMediaDataSchema),\n\t\tcreateOutputItemSchema(z.literal(\"SVG\"), VirtualMediaDataSchema),\n\t\tcreateOutputItemSchema(z.literal(\"GIF\"), VirtualMediaDataSchema),\n\t]),\n);\n\nexport type MeshWarpResult = z.infer<typeof MeshWarpResultSchema>;\n\nexport const WARP_OUTPUT_TYPE_MAP: Record<\n\tstring,\n\t\"Image\" | \"Video\" | \"GIF\" | \"SVG\"\n> = {\n\tVideo: \"Video\",\n\tLottie: \"Video\",\n\tGIF: \"GIF\",\n\tImage: \"Image\",\n\tSVG: \"Image\",\n};\n"],"mappings":";;;;;AAOA,MAAa,2BAA2B,EACtC,OAAO;CACP,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE;CAChD,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE;CAChD,QAAQ,EACN,MACA,EAAE,OAAO;EACR,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;EAC7B,GAAG,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;EAC7B,CAAC,CACF,CACA,IAAI,IAAI,CACR,UAAU;CACZ,CAAC,CACD,QAAQ,CACR,aAAa,MAAM,QAAQ;AAC3B,KAAI,KAAK,UAAU,KAAK,OAAO,SAAS,GAAG;EAC1C,MAAM,WAAW,KAAK,OAAO,KAAK;AAClC,MAAI,KAAK,OAAO,WAAW,SAC1B,KAAI,SAAS;GACZ,MAAM,EAAE,aAAa;GACrB,MAAM,CAAC,SAAS;GAChB,SAAS,kCAAkC,SAAS,kCAAkC,KAAK,OAAO;GAClG,CAAC;;EAGH;AAIH,MAAa,0BAA0B,yBAAyB,OAAO;CACtE,IAAI,EAAE,QAAQ,WAAW;CACzB,UAAU,EAAE,KAAK,CAAC,UAAU;CAC5B,CAAC;AAIF,MAAa,uBAAuB,0BACnC,EAAE,MAAM;CACP,uBAAuB,EAAE,QAAQ,QAAQ,EAAE,uBAAuB;CAClE,uBAAuB,EAAE,QAAQ,QAAQ,EAAE,uBAAuB;CAClE,uBAAuB,EAAE,QAAQ,MAAM,EAAE,uBAAuB;CAChE,uBAAuB,EAAE,QAAQ,MAAM,EAAE,uBAAuB;CAChE,CAAC,CACF;AAID,MAAa,uBAGT;CACH,OAAO;CACP,QAAQ;CACR,KAAK;CACL,OAAO;CACP,KAAK;CACL"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _framefields_node_sdk_renderer0 from "@framefields/node-sdk/renderer";
|
|
2
|
+
|
|
3
|
+
//#region src/renderers/index.d.ts
|
|
4
|
+
declare const _default: Readonly<_framefields_node_sdk_renderer0.NodeRendererPlugin>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { _default as default };
|
|
7
|
+
//# sourceMappingURL=renderer.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.mts","names":[],"sources":["../src/renderers/index.ts"],"sourcesContent":[],"mappings":""}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { defineRenderer } from "@framefields/node-sdk/renderer";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/utils.ts
|
|
4
|
+
function createUniformGrid(cols, rows) {
|
|
5
|
+
const points = [];
|
|
6
|
+
for (let r = 0; r < rows; r++) {
|
|
7
|
+
const y = r / (rows - 1) * 100;
|
|
8
|
+
for (let c = 0; c < cols; c++) {
|
|
9
|
+
const x = c / (cols - 1) * 100;
|
|
10
|
+
points.push({
|
|
11
|
+
x,
|
|
12
|
+
y
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return points;
|
|
17
|
+
}
|
|
18
|
+
function interpolateGridPoint(u, v, oldPoints, oldCols, oldRows) {
|
|
19
|
+
const px = u * (oldCols - 1);
|
|
20
|
+
const py = v * (oldRows - 1);
|
|
21
|
+
const x0 = Math.floor(px);
|
|
22
|
+
const x1 = Math.min(oldCols - 1, x0 + 1);
|
|
23
|
+
const y0 = Math.floor(py);
|
|
24
|
+
const y1 = Math.min(oldRows - 1, y0 + 1);
|
|
25
|
+
const tx = px - x0;
|
|
26
|
+
const ty = py - y0;
|
|
27
|
+
const p00 = oldPoints[y0 * oldCols + x0];
|
|
28
|
+
const p10 = oldPoints[y0 * oldCols + x1];
|
|
29
|
+
const p01 = oldPoints[y1 * oldCols + x0];
|
|
30
|
+
const p11 = oldPoints[y1 * oldCols + x1];
|
|
31
|
+
if (!p00 || !p10 || !p01 || !p11) return {
|
|
32
|
+
x: u * 100,
|
|
33
|
+
y: v * 100
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
x: (1 - tx) * (1 - ty) * p00.x + tx * (1 - ty) * p10.x + (1 - tx) * ty * p01.x + tx * ty * p11.x,
|
|
37
|
+
y: (1 - tx) * (1 - ty) * p00.y + tx * (1 - ty) * p10.y + (1 - tx) * ty * p01.y + tx * ty * p11.y
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function resizeGrid(oldPoints, oldCols, oldRows, newCols, newRows) {
|
|
41
|
+
if (!oldPoints || oldPoints.length !== oldCols * oldRows) return createUniformGrid(newCols, newRows);
|
|
42
|
+
const points = [];
|
|
43
|
+
for (let r = 0; r < newRows; r++) {
|
|
44
|
+
const v = r / (newRows - 1);
|
|
45
|
+
for (let c = 0; c < newCols; c++) {
|
|
46
|
+
const u = c / (newCols - 1);
|
|
47
|
+
points.push(interpolateGridPoint(u, v, oldPoints, oldCols, oldRows));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return points;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/renderers/webgpu-renderer.ts
|
|
55
|
+
const meshWarpWgsl = `
|
|
56
|
+
struct MeshUniforms {
|
|
57
|
+
gridSize : vec2<f32>,
|
|
58
|
+
layerSize : vec2<f32>,
|
|
59
|
+
matrix_col0 : vec4<f32>,
|
|
60
|
+
matrix_col1 : vec4<f32>,
|
|
61
|
+
points : array<vec4<f32>, 144>,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
@group(0) @binding(0) var<uniform> u : MeshUniforms;
|
|
65
|
+
@group(1) @binding(0) var tex : texture_2d<f32>;
|
|
66
|
+
@group(1) @binding(1) var samp : sampler;
|
|
67
|
+
|
|
68
|
+
struct VSOut {
|
|
69
|
+
@builtin(position) pos : vec4<f32>,
|
|
70
|
+
@location(0) uv : vec2<f32>,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
@vertex fn vs(@builtin(vertex_index) vi: u32) -> VSOut {
|
|
74
|
+
let cols = u32(u.gridSize.x);
|
|
75
|
+
let rows = u32(u.gridSize.y);
|
|
76
|
+
|
|
77
|
+
let cellsCol = cols - 1u;
|
|
78
|
+
let cellsRow = rows - 1u;
|
|
79
|
+
let totalCells = cellsCol * cellsRow;
|
|
80
|
+
|
|
81
|
+
let cellIndex = vi / 6u;
|
|
82
|
+
let vertexInCell = vi % 6u;
|
|
83
|
+
|
|
84
|
+
if (cellIndex >= totalCells) {
|
|
85
|
+
return VSOut(vec4<f32>(0.0), vec4<f32>(0.0).xy);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let cellC = cellIndex % cellsCol;
|
|
89
|
+
let cellR = cellIndex / cellsCol;
|
|
90
|
+
|
|
91
|
+
var colOffset = 0u;
|
|
92
|
+
var rowOffset = 0u;
|
|
93
|
+
|
|
94
|
+
// Mapping vertex index in cell to quad corner offset
|
|
95
|
+
// Triangle 1: TL (0,0), TR (1,0), BL (0,1)
|
|
96
|
+
// Triangle 2: TR (1,0), BR (1,1), BL (0,1)
|
|
97
|
+
if (vertexInCell == 1u) { // TR
|
|
98
|
+
colOffset = 1u;
|
|
99
|
+
rowOffset = 0u;
|
|
100
|
+
} else if (vertexInCell == 2u) { // BL
|
|
101
|
+
colOffset = 0u;
|
|
102
|
+
rowOffset = 1u;
|
|
103
|
+
} else if (vertexInCell == 3u) { // TR
|
|
104
|
+
colOffset = 1u;
|
|
105
|
+
rowOffset = 0u;
|
|
106
|
+
} else if (vertexInCell == 4u) { // BR
|
|
107
|
+
colOffset = 1u;
|
|
108
|
+
rowOffset = 1u;
|
|
109
|
+
} else if (vertexInCell == 5u) { // BL
|
|
110
|
+
colOffset = 0u;
|
|
111
|
+
rowOffset = 1u;
|
|
112
|
+
}
|
|
113
|
+
// Vertex 0 is TL (colOffset=0, rowOffset=0)
|
|
114
|
+
|
|
115
|
+
let gridC = cellC + colOffset;
|
|
116
|
+
let gridR = cellR + rowOffset;
|
|
117
|
+
|
|
118
|
+
let pointIndex = gridR * cols + gridC;
|
|
119
|
+
let warpedPoint = u.points[pointIndex].xy;
|
|
120
|
+
|
|
121
|
+
let lx = (warpedPoint.x / 100.0) * u.layerSize.x;
|
|
122
|
+
let ly = (warpedPoint.y / 100.0) * u.layerSize.y;
|
|
123
|
+
|
|
124
|
+
let tx = u.matrix_col0.x * lx + u.matrix_col0.y * ly + u.matrix_col0.z;
|
|
125
|
+
let ty = u.matrix_col1.x * lx + u.matrix_col1.y * ly + u.matrix_col1.z;
|
|
126
|
+
|
|
127
|
+
let targetW = u.matrix_col0.w;
|
|
128
|
+
let targetH = u.matrix_col1.w;
|
|
129
|
+
|
|
130
|
+
let x_clip = (tx / targetW) * 2.0 - 1.0;
|
|
131
|
+
let y_clip = 1.0 - (ty / targetH) * 2.0;
|
|
132
|
+
|
|
133
|
+
let u_coord = f32(gridC) / f32(cellsCol);
|
|
134
|
+
let v_coord = f32(gridR) / f32(cellsRow);
|
|
135
|
+
|
|
136
|
+
return VSOut(vec4<f32>(x_clip, y_clip, 0.0, 1.0), vec2<f32>(u_coord, v_coord));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@fragment fn fs(in : VSOut) -> @location(0) vec4<f32> {
|
|
140
|
+
let color = textureSampleLevel(tex, samp, in.uv, 0.0);
|
|
141
|
+
return color;
|
|
142
|
+
}
|
|
143
|
+
`;
|
|
144
|
+
const deviceResourceCache = /* @__PURE__ */ new WeakMap();
|
|
145
|
+
function getMeshWarpResources(device, format) {
|
|
146
|
+
let res = deviceResourceCache.get(device);
|
|
147
|
+
if (!res) {
|
|
148
|
+
const warpUniformLayout = device.createBindGroupLayout({ entries: [{
|
|
149
|
+
binding: 0,
|
|
150
|
+
visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
|
|
151
|
+
buffer: { type: "uniform" }
|
|
152
|
+
}] });
|
|
153
|
+
const warpTextureLayout = device.createBindGroupLayout({ entries: [{
|
|
154
|
+
binding: 0,
|
|
155
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
156
|
+
texture: { sampleType: "float" }
|
|
157
|
+
}, {
|
|
158
|
+
binding: 1,
|
|
159
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
160
|
+
sampler: { type: "filtering" }
|
|
161
|
+
}] });
|
|
162
|
+
const module = device.createShaderModule({
|
|
163
|
+
label: "mesh_warp.wgsl",
|
|
164
|
+
code: meshWarpWgsl
|
|
165
|
+
});
|
|
166
|
+
res = {
|
|
167
|
+
warpPipeline: device.createRenderPipeline({
|
|
168
|
+
label: "MeshWarpPipeline",
|
|
169
|
+
layout: device.createPipelineLayout({ bindGroupLayouts: [warpUniformLayout, warpTextureLayout] }),
|
|
170
|
+
vertex: {
|
|
171
|
+
module,
|
|
172
|
+
entryPoint: "vs"
|
|
173
|
+
},
|
|
174
|
+
fragment: {
|
|
175
|
+
module,
|
|
176
|
+
entryPoint: "fs",
|
|
177
|
+
targets: [{
|
|
178
|
+
format,
|
|
179
|
+
blend: {
|
|
180
|
+
color: {
|
|
181
|
+
srcFactor: "src-alpha",
|
|
182
|
+
dstFactor: "one-minus-src-alpha",
|
|
183
|
+
operation: "add"
|
|
184
|
+
},
|
|
185
|
+
alpha: {
|
|
186
|
+
srcFactor: "one",
|
|
187
|
+
dstFactor: "one-minus-src-alpha",
|
|
188
|
+
operation: "add"
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}]
|
|
192
|
+
},
|
|
193
|
+
primitive: { topology: "triangle-list" }
|
|
194
|
+
}),
|
|
195
|
+
warpUniformLayout,
|
|
196
|
+
warpTextureLayout
|
|
197
|
+
};
|
|
198
|
+
deviceResourceCache.set(device, res);
|
|
199
|
+
}
|
|
200
|
+
return res;
|
|
201
|
+
}
|
|
202
|
+
const MeshWarpWebGPURenderer = async (args) => {
|
|
203
|
+
const { ctx, props, drawChild, targetTexture, targetView, targetWidth, targetHeight, encoder } = args;
|
|
204
|
+
const { virtualMedia } = props;
|
|
205
|
+
const op = virtualMedia?.operation;
|
|
206
|
+
if (!op || op.op !== "MeshWarp") return;
|
|
207
|
+
const childMedia = virtualMedia.children?.[0];
|
|
208
|
+
if (!childMedia) return;
|
|
209
|
+
const sourceWidth = op.originalWidth ?? childMedia.metadata?.width ?? props.containerWidth ?? targetWidth;
|
|
210
|
+
const sourceHeight = op.originalHeight ?? childMedia.metadata?.height ?? props.containerHeight ?? targetHeight;
|
|
211
|
+
args.pass.end();
|
|
212
|
+
const childTex = ctx.renderer.getTemporaryTexture(sourceWidth, sourceHeight, [...props.excludeTextures || [], targetTexture]);
|
|
213
|
+
const childView = childTex.createView();
|
|
214
|
+
ctx.renderer.beginFrame(encoder, childView, {
|
|
215
|
+
r: 0,
|
|
216
|
+
g: 0,
|
|
217
|
+
b: 0,
|
|
218
|
+
a: 0
|
|
219
|
+
}, sourceWidth, sourceHeight, "clear").end();
|
|
220
|
+
ctx.renderer.pushScissor({
|
|
221
|
+
x: 0,
|
|
222
|
+
y: 0,
|
|
223
|
+
width: sourceWidth,
|
|
224
|
+
height: sourceHeight
|
|
225
|
+
});
|
|
226
|
+
ctx.renderer.pushIdentity();
|
|
227
|
+
await drawChild(childMedia, {
|
|
228
|
+
...props,
|
|
229
|
+
containerWidth: sourceWidth,
|
|
230
|
+
containerHeight: sourceHeight
|
|
231
|
+
}, childView, childTex, sourceWidth, sourceHeight);
|
|
232
|
+
ctx.renderer.popTransform();
|
|
233
|
+
ctx.renderer.popScissor();
|
|
234
|
+
const cols = Number(op.cols) || 3;
|
|
235
|
+
const rows = Number(op.rows) || 3;
|
|
236
|
+
const points = op.points || [];
|
|
237
|
+
const finalPoints = points.length === cols * rows ? points : createUniformGrid(cols, rows);
|
|
238
|
+
const maxPoints = 144;
|
|
239
|
+
const uniformData = new Float32Array(12 + maxPoints * 4);
|
|
240
|
+
uniformData[0] = cols;
|
|
241
|
+
uniformData[1] = rows;
|
|
242
|
+
uniformData[2] = props.containerWidth ?? sourceWidth;
|
|
243
|
+
uniformData[3] = props.containerHeight ?? sourceHeight;
|
|
244
|
+
const matrix = ctx.renderer.getCurrentTransform();
|
|
245
|
+
uniformData[4] = matrix.a;
|
|
246
|
+
uniformData[5] = matrix.c;
|
|
247
|
+
uniformData[6] = matrix.e;
|
|
248
|
+
uniformData[7] = targetWidth;
|
|
249
|
+
uniformData[8] = matrix.b;
|
|
250
|
+
uniformData[9] = matrix.d;
|
|
251
|
+
uniformData[10] = matrix.f;
|
|
252
|
+
uniformData[11] = targetHeight;
|
|
253
|
+
for (let i = 0; i < maxPoints; i++) {
|
|
254
|
+
const pt = finalPoints[i] || {
|
|
255
|
+
x: 0,
|
|
256
|
+
y: 0
|
|
257
|
+
};
|
|
258
|
+
uniformData[12 + i * 4] = pt.x;
|
|
259
|
+
uniformData[12 + i * 4 + 1] = pt.y;
|
|
260
|
+
}
|
|
261
|
+
const { warpPipeline: pipeline, warpUniformLayout: uLayout, warpTextureLayout: tLayout } = getMeshWarpResources(ctx.device, ctx.renderer.format);
|
|
262
|
+
const sampler = ctx.renderer.samplerCache.getSampler(ctx.device);
|
|
263
|
+
const uniformBuffer = ctx.renderer.getTemporaryBuffer(uniformData);
|
|
264
|
+
const uniformBindGroup = ctx.device.createBindGroup({
|
|
265
|
+
layout: uLayout,
|
|
266
|
+
entries: [{
|
|
267
|
+
binding: 0,
|
|
268
|
+
resource: { buffer: uniformBuffer }
|
|
269
|
+
}]
|
|
270
|
+
});
|
|
271
|
+
const textureBindGroup = ctx.renderer.bindGroupCache.getBindGroup(ctx.device, tLayout, childTex, sampler);
|
|
272
|
+
const outPass = ctx.renderer.beginFrame(encoder, targetView, {
|
|
273
|
+
r: 0,
|
|
274
|
+
g: 0,
|
|
275
|
+
b: 0,
|
|
276
|
+
a: 0
|
|
277
|
+
}, targetWidth, targetHeight, "load");
|
|
278
|
+
outPass.setPipeline(pipeline);
|
|
279
|
+
outPass.setBindGroup(0, uniformBindGroup);
|
|
280
|
+
outPass.setBindGroup(1, textureBindGroup);
|
|
281
|
+
const vertexCount = (cols - 1) * (rows - 1) * 6;
|
|
282
|
+
outPass.draw(vertexCount);
|
|
283
|
+
args.pass = outPass;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/renderers/index.ts
|
|
288
|
+
var renderers_default = defineRenderer({ WebGPURenderer: MeshWarpWebGPURenderer });
|
|
289
|
+
|
|
290
|
+
//#endregion
|
|
291
|
+
export { resizeGrid as i, createUniformGrid as n, interpolateGridPoint as r, renderers_default as t };
|
|
292
|
+
//# sourceMappingURL=renderers-DzkHlv-9.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers-DzkHlv-9.mjs","names":[],"sources":["../src/shared/utils.ts","../src/renderers/webgpu-renderer.ts","../src/renderers/index.ts"],"sourcesContent":["export function createUniformGrid(cols: number, rows: number) {\n\tconst points: { x: number; y: number }[] = [];\n\tfor (let r = 0; r < rows; r++) {\n\t\tconst y = (r / (rows - 1)) * 100;\n\t\tfor (let c = 0; c < cols; c++) {\n\t\t\tconst x = (c / (cols - 1)) * 100;\n\t\t\tpoints.push({ x, y });\n\t\t}\n\t}\n\treturn points;\n}\n\nexport function interpolateGridPoint(\n\tu: number,\n\tv: number,\n\toldPoints: { x: number; y: number }[],\n\toldCols: number,\n\toldRows: number,\n) {\n\tconst px = u * (oldCols - 1);\n\tconst py = v * (oldRows - 1);\n\n\tconst x0 = Math.floor(px);\n\tconst x1 = Math.min(oldCols - 1, x0 + 1);\n\tconst y0 = Math.floor(py);\n\tconst y1 = Math.min(oldRows - 1, y0 + 1);\n\n\tconst tx = px - x0;\n\tconst ty = py - y0;\n\n\tconst p00 = oldPoints[y0 * oldCols + x0];\n\tconst p10 = oldPoints[y0 * oldCols + x1];\n\tconst p01 = oldPoints[y1 * oldCols + x0];\n\tconst p11 = oldPoints[y1 * oldCols + x1];\n\n\tif (!p00 || !p10 || !p01 || !p11) {\n\t\treturn { x: u * 100, y: v * 100 };\n\t}\n\n\tconst x =\n\t\t(1 - tx) * (1 - ty) * p00.x +\n\t\ttx * (1 - ty) * p10.x +\n\t\t(1 - tx) * ty * p01.x +\n\t\ttx * ty * p11.x;\n\n\tconst y =\n\t\t(1 - tx) * (1 - ty) * p00.y +\n\t\ttx * (1 - ty) * p10.y +\n\t\t(1 - tx) * ty * p01.y +\n\t\ttx * ty * p11.y;\n\n\treturn { x, y };\n}\n\nexport function resizeGrid(\n\toldPoints: { x: number; y: number }[] | undefined | null,\n\toldCols: number,\n\toldRows: number,\n\tnewCols: number,\n\tnewRows: number,\n) {\n\tif (!oldPoints || oldPoints.length !== oldCols * oldRows) {\n\t\treturn createUniformGrid(newCols, newRows);\n\t}\n\tconst points: { x: number; y: number }[] = [];\n\tfor (let r = 0; r < newRows; r++) {\n\t\tconst v = r / (newRows - 1);\n\t\tfor (let c = 0; c < newCols; c++) {\n\t\t\tconst u = c / (newCols - 1);\n\t\t\tpoints.push(interpolateGridPoint(u, v, oldPoints, oldCols, oldRows));\n\t\t}\n\t}\n\treturn points;\n}\n","import type { WebGPUNodeRenderer } from \"@framefields/node-sdk\";\nimport { createUniformGrid } from \"../shared/utils.js\";\n\nconst meshWarpWgsl = `\nstruct MeshUniforms {\n\tgridSize : vec2<f32>,\n\tlayerSize : vec2<f32>,\n\tmatrix_col0 : vec4<f32>,\n\tmatrix_col1 : vec4<f32>,\n\tpoints : array<vec4<f32>, 144>,\n};\n\n@group(0) @binding(0) var<uniform> u : MeshUniforms;\n@group(1) @binding(0) var tex : texture_2d<f32>;\n@group(1) @binding(1) var samp : sampler;\n\nstruct VSOut {\n\t@builtin(position) pos : vec4<f32>,\n\t@location(0) uv : vec2<f32>,\n};\n\n@vertex fn vs(@builtin(vertex_index) vi: u32) -> VSOut {\n\tlet cols = u32(u.gridSize.x);\n\tlet rows = u32(u.gridSize.y);\n\t\n\tlet cellsCol = cols - 1u;\n\tlet cellsRow = rows - 1u;\n\tlet totalCells = cellsCol * cellsRow;\n\t\n\tlet cellIndex = vi / 6u;\n\tlet vertexInCell = vi % 6u;\n\t\n\tif (cellIndex >= totalCells) {\n\t\treturn VSOut(vec4<f32>(0.0), vec4<f32>(0.0).xy);\n\t}\n\t\n\tlet cellC = cellIndex % cellsCol;\n\tlet cellR = cellIndex / cellsCol;\n\t\n\tvar colOffset = 0u;\n\tvar rowOffset = 0u;\n\t\n\t// Mapping vertex index in cell to quad corner offset\n\t// Triangle 1: TL (0,0), TR (1,0), BL (0,1)\n\t// Triangle 2: TR (1,0), BR (1,1), BL (0,1)\n\tif (vertexInCell == 1u) { // TR\n\t\tcolOffset = 1u;\n\t\trowOffset = 0u;\n\t} else if (vertexInCell == 2u) { // BL\n\t\tcolOffset = 0u;\n\t\trowOffset = 1u;\n\t} else if (vertexInCell == 3u) { // TR\n\t\tcolOffset = 1u;\n\t\trowOffset = 0u;\n\t} else if (vertexInCell == 4u) { // BR\n\t\tcolOffset = 1u;\n\t\trowOffset = 1u;\n\t} else if (vertexInCell == 5u) { // BL\n\t\tcolOffset = 0u;\n\t\trowOffset = 1u;\n\t}\n\t// Vertex 0 is TL (colOffset=0, rowOffset=0)\n\t\n\tlet gridC = cellC + colOffset;\n\tlet gridR = cellR + rowOffset;\n\t\n\tlet pointIndex = gridR * cols + gridC;\n\tlet warpedPoint = u.points[pointIndex].xy;\n\t\n\tlet lx = (warpedPoint.x / 100.0) * u.layerSize.x;\n\tlet ly = (warpedPoint.y / 100.0) * u.layerSize.y;\n\t\n\tlet tx = u.matrix_col0.x * lx + u.matrix_col0.y * ly + u.matrix_col0.z;\n\tlet ty = u.matrix_col1.x * lx + u.matrix_col1.y * ly + u.matrix_col1.z;\n\t\n\tlet targetW = u.matrix_col0.w;\n\tlet targetH = u.matrix_col1.w;\n\t\n\tlet x_clip = (tx / targetW) * 2.0 - 1.0;\n\tlet y_clip = 1.0 - (ty / targetH) * 2.0;\n\t\n\tlet u_coord = f32(gridC) / f32(cellsCol);\n\tlet v_coord = f32(gridR) / f32(cellsRow);\n\t\n\treturn VSOut(vec4<f32>(x_clip, y_clip, 0.0, 1.0), vec2<f32>(u_coord, v_coord));\n}\n\n@fragment fn fs(in : VSOut) -> @location(0) vec4<f32> {\n\tlet color = textureSampleLevel(tex, samp, in.uv, 0.0);\n\treturn color;\n}\n`;\n\ninterface DeviceMeshWarpResources {\n\twarpPipeline: GPURenderPipeline;\n\twarpUniformLayout: GPUBindGroupLayout;\n\twarpTextureLayout: GPUBindGroupLayout;\n}\n\nconst deviceResourceCache = new WeakMap<GPUDevice, DeviceMeshWarpResources>();\n\nfunction getMeshWarpResources(device: GPUDevice, format: GPUTextureFormat) {\n\tlet res = deviceResourceCache.get(device);\n\tif (!res) {\n\t\tconst warpUniformLayout = device.createBindGroupLayout({\n\t\t\tentries: [\n\t\t\t\t{\n\t\t\t\t\tbinding: 0,\n\t\t\t\t\tvisibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,\n\t\t\t\t\tbuffer: { type: \"uniform\" },\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\tconst warpTextureLayout = device.createBindGroupLayout({\n\t\t\tentries: [\n\t\t\t\t{\n\t\t\t\t\tbinding: 0,\n\t\t\t\t\tvisibility: GPUShaderStage.FRAGMENT,\n\t\t\t\t\ttexture: { sampleType: \"float\" },\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tbinding: 1,\n\t\t\t\t\tvisibility: GPUShaderStage.FRAGMENT,\n\t\t\t\t\tsampler: { type: \"filtering\" },\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\n\t\tconst module = device.createShaderModule({\n\t\t\tlabel: \"mesh_warp.wgsl\",\n\t\t\tcode: meshWarpWgsl,\n\t\t});\n\n\t\tconst warpPipeline = device.createRenderPipeline({\n\t\t\tlabel: \"MeshWarpPipeline\",\n\t\t\tlayout: device.createPipelineLayout({\n\t\t\t\tbindGroupLayouts: [warpUniformLayout, warpTextureLayout],\n\t\t\t}),\n\t\t\tvertex: {\n\t\t\t\tmodule,\n\t\t\t\tentryPoint: \"vs\",\n\t\t\t},\n\t\t\tfragment: {\n\t\t\t\tmodule,\n\t\t\t\tentryPoint: \"fs\",\n\t\t\t\ttargets: [\n\t\t\t\t\t{\n\t\t\t\t\t\tformat,\n\t\t\t\t\t\tblend: {\n\t\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\t\tsrcFactor: \"src-alpha\",\n\t\t\t\t\t\t\t\tdstFactor: \"one-minus-src-alpha\",\n\t\t\t\t\t\t\t\toperation: \"add\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\talpha: {\n\t\t\t\t\t\t\t\tsrcFactor: \"one\",\n\t\t\t\t\t\t\t\tdstFactor: \"one-minus-src-alpha\",\n\t\t\t\t\t\t\t\toperation: \"add\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\tprimitive: {\n\t\t\t\ttopology: \"triangle-list\",\n\t\t\t},\n\t\t});\n\n\t\tres = { warpPipeline, warpUniformLayout, warpTextureLayout };\n\t\tdeviceResourceCache.set(device, res);\n\t}\n\treturn res;\n}\n\nexport const MeshWarpWebGPURenderer: WebGPUNodeRenderer = async (args) => {\n\tconst {\n\t\tctx,\n\t\tprops,\n\t\tdrawChild,\n\t\ttargetTexture,\n\t\ttargetView,\n\t\ttargetWidth,\n\t\ttargetHeight,\n\t\tencoder,\n\t} = args;\n\tconst { virtualMedia } = props;\n\tconst op = virtualMedia?.operation as any;\n\tif (!op || op.op !== \"MeshWarp\") return;\n\n\tconst childMedia = virtualMedia.children?.[0];\n\tif (!childMedia) return;\n\n\tconst sourceWidth =\n\t\top.originalWidth ??\n\t\tchildMedia.metadata?.width ??\n\t\tprops.containerWidth ??\n\t\ttargetWidth;\n\tconst sourceHeight =\n\t\top.originalHeight ??\n\t\tchildMedia.metadata?.height ??\n\t\tprops.containerHeight ??\n\t\ttargetHeight;\n\n\t// End incoming pass to avoid conflicts\n\targs.pass.end();\n\n\t// 1. Render child into a temporary offscreen texture at its native size\n\tconst childTex = ctx.renderer.getTemporaryTexture(sourceWidth, sourceHeight, [\n\t\t...(props.excludeTextures || []),\n\t\ttargetTexture,\n\t]);\n\tconst childView = childTex.createView();\n\n\tconst clearPass = ctx.renderer.beginFrame(\n\t\tencoder,\n\t\tchildView,\n\t\t{ r: 0, g: 0, b: 0, a: 0 },\n\t\tsourceWidth,\n\t\tsourceHeight,\n\t\t\"clear\",\n\t);\n\tclearPass.end();\n\n\tctx.renderer.pushScissor({\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth: sourceWidth,\n\t\theight: sourceHeight,\n\t});\n\tctx.renderer.pushIdentity();\n\n\tawait drawChild(\n\t\tchildMedia,\n\t\t{\n\t\t\t...props,\n\t\t\tcontainerWidth: sourceWidth,\n\t\t\tcontainerHeight: sourceHeight,\n\t\t},\n\t\tchildView,\n\t\tchildTex,\n\t\tsourceWidth,\n\t\tsourceHeight,\n\t);\n\n\tctx.renderer.popTransform();\n\tctx.renderer.popScissor();\n\n\t// 2. Setup warp rendering to targetView\n\tconst cols = Number(op.cols) || 3;\n\tconst rows = Number(op.rows) || 3;\n\tconst points = op.points || [];\n\n\tconst finalPoints =\n\t\tpoints.length === cols * rows ? points : createUniformGrid(cols, rows);\n\n\t// Setup uniforms: gridSize (vec2), layerSize (vec2), matrix_col0 (vec4), matrix_col1 (vec4), then 144 points\n\tconst maxPoints = 144;\n\tconst uniformData = new Float32Array(12 + maxPoints * 4);\n\tuniformData[0] = cols;\n\tuniformData[1] = rows;\n\tuniformData[2] = props.containerWidth ?? sourceWidth;\n\tuniformData[3] = props.containerHeight ?? sourceHeight;\n\n\tconst matrix = ctx.renderer.getCurrentTransform();\n\tuniformData[4] = matrix.a;\n\tuniformData[5] = matrix.c;\n\tuniformData[6] = matrix.e;\n\tuniformData[7] = targetWidth;\n\n\tuniformData[8] = matrix.b;\n\tuniformData[9] = matrix.d;\n\tuniformData[10] = matrix.f;\n\tuniformData[11] = targetHeight;\n\n\tfor (let i = 0; i < maxPoints; i++) {\n\t\tconst pt = finalPoints[i] || { x: 0, y: 0 };\n\t\tuniformData[12 + i * 4] = pt.x;\n\t\tuniformData[12 + i * 4 + 1] = pt.y;\n\t}\n\n\tconst {\n\t\twarpPipeline: pipeline,\n\t\twarpUniformLayout: uLayout,\n\t\twarpTextureLayout: tLayout,\n\t} = getMeshWarpResources(ctx.device, ctx.renderer.format);\n\n\tconst sampler = ctx.renderer.samplerCache.getSampler(ctx.device);\n\tconst uniformBuffer = ctx.renderer.getTemporaryBuffer(uniformData);\n\n\tconst uniformBindGroup = ctx.device.createBindGroup({\n\t\tlayout: uLayout!,\n\t\tentries: [{ binding: 0, resource: { buffer: uniformBuffer } }],\n\t});\n\n\tconst textureBindGroup = ctx.renderer.bindGroupCache.getBindGroup(\n\t\tctx.device,\n\t\ttLayout!,\n\t\tchildTex,\n\t\tsampler,\n\t);\n\n\tconst outPass = ctx.renderer.beginFrame(\n\t\tencoder,\n\t\ttargetView,\n\t\t{ r: 0, g: 0, b: 0, a: 0 },\n\t\ttargetWidth,\n\t\ttargetHeight,\n\t\t\"load\",\n\t);\n\n\toutPass.setPipeline(pipeline!);\n\toutPass.setBindGroup(0, uniformBindGroup);\n\toutPass.setBindGroup(1, textureBindGroup);\n\n\tconst cellCount = (cols - 1) * (rows - 1);\n\tconst vertexCount = cellCount * 6;\n\toutPass.draw(vertexCount);\n\n\targs.pass = outPass;\n};\n","import { defineRenderer } from \"@framefields/node-sdk/renderer\";\nimport { MeshWarpWebGPURenderer } from \"./webgpu-renderer.js\";\n\nexport default defineRenderer({\n\tWebGPURenderer: MeshWarpWebGPURenderer,\n});\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@framefields/node-mesh-warp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"private": false,
|
|
6
|
+
"framefields": {
|
|
7
|
+
"type": "MeshWarp",
|
|
8
|
+
"kind": "effect"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.mts",
|
|
16
|
+
"development": "./src/index.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"default": "./dist/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./renderer": {
|
|
21
|
+
"types": "./dist/renderer.d.mts",
|
|
22
|
+
"development": "./src/renderers/index.ts",
|
|
23
|
+
"import": "./dist/renderer.mjs",
|
|
24
|
+
"default": "./dist/renderer.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"zod": "^4.3.6",
|
|
29
|
+
"@framefields/core": "2.0.3",
|
|
30
|
+
"@framefields/node-sdk": "2.0.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.1.0",
|
|
34
|
+
"tsdown": "^0.19.0",
|
|
35
|
+
"typescript": "^5.8.3",
|
|
36
|
+
"@framefields/tsconfig": "2.0.3"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsdown",
|
|
43
|
+
"dev": "tsdown --watch",
|
|
44
|
+
"clean": "rm -rf dist"
|
|
45
|
+
}
|
|
6
46
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import type { WebGPUNodeRenderer } from "@framefields/node-sdk";
|
|
2
|
+
import { createUniformGrid } from "../shared/utils.js";
|
|
3
|
+
|
|
4
|
+
const meshWarpWgsl = `
|
|
5
|
+
struct MeshUniforms {
|
|
6
|
+
gridSize : vec2<f32>,
|
|
7
|
+
layerSize : vec2<f32>,
|
|
8
|
+
matrix_col0 : vec4<f32>,
|
|
9
|
+
matrix_col1 : vec4<f32>,
|
|
10
|
+
points : array<vec4<f32>, 144>,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
@group(0) @binding(0) var<uniform> u : MeshUniforms;
|
|
14
|
+
@group(1) @binding(0) var tex : texture_2d<f32>;
|
|
15
|
+
@group(1) @binding(1) var samp : sampler;
|
|
16
|
+
|
|
17
|
+
struct VSOut {
|
|
18
|
+
@builtin(position) pos : vec4<f32>,
|
|
19
|
+
@location(0) uv : vec2<f32>,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
@vertex fn vs(@builtin(vertex_index) vi: u32) -> VSOut {
|
|
23
|
+
let cols = u32(u.gridSize.x);
|
|
24
|
+
let rows = u32(u.gridSize.y);
|
|
25
|
+
|
|
26
|
+
let cellsCol = cols - 1u;
|
|
27
|
+
let cellsRow = rows - 1u;
|
|
28
|
+
let totalCells = cellsCol * cellsRow;
|
|
29
|
+
|
|
30
|
+
let cellIndex = vi / 6u;
|
|
31
|
+
let vertexInCell = vi % 6u;
|
|
32
|
+
|
|
33
|
+
if (cellIndex >= totalCells) {
|
|
34
|
+
return VSOut(vec4<f32>(0.0), vec4<f32>(0.0).xy);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let cellC = cellIndex % cellsCol;
|
|
38
|
+
let cellR = cellIndex / cellsCol;
|
|
39
|
+
|
|
40
|
+
var colOffset = 0u;
|
|
41
|
+
var rowOffset = 0u;
|
|
42
|
+
|
|
43
|
+
// Mapping vertex index in cell to quad corner offset
|
|
44
|
+
// Triangle 1: TL (0,0), TR (1,0), BL (0,1)
|
|
45
|
+
// Triangle 2: TR (1,0), BR (1,1), BL (0,1)
|
|
46
|
+
if (vertexInCell == 1u) { // TR
|
|
47
|
+
colOffset = 1u;
|
|
48
|
+
rowOffset = 0u;
|
|
49
|
+
} else if (vertexInCell == 2u) { // BL
|
|
50
|
+
colOffset = 0u;
|
|
51
|
+
rowOffset = 1u;
|
|
52
|
+
} else if (vertexInCell == 3u) { // TR
|
|
53
|
+
colOffset = 1u;
|
|
54
|
+
rowOffset = 0u;
|
|
55
|
+
} else if (vertexInCell == 4u) { // BR
|
|
56
|
+
colOffset = 1u;
|
|
57
|
+
rowOffset = 1u;
|
|
58
|
+
} else if (vertexInCell == 5u) { // BL
|
|
59
|
+
colOffset = 0u;
|
|
60
|
+
rowOffset = 1u;
|
|
61
|
+
}
|
|
62
|
+
// Vertex 0 is TL (colOffset=0, rowOffset=0)
|
|
63
|
+
|
|
64
|
+
let gridC = cellC + colOffset;
|
|
65
|
+
let gridR = cellR + rowOffset;
|
|
66
|
+
|
|
67
|
+
let pointIndex = gridR * cols + gridC;
|
|
68
|
+
let warpedPoint = u.points[pointIndex].xy;
|
|
69
|
+
|
|
70
|
+
let lx = (warpedPoint.x / 100.0) * u.layerSize.x;
|
|
71
|
+
let ly = (warpedPoint.y / 100.0) * u.layerSize.y;
|
|
72
|
+
|
|
73
|
+
let tx = u.matrix_col0.x * lx + u.matrix_col0.y * ly + u.matrix_col0.z;
|
|
74
|
+
let ty = u.matrix_col1.x * lx + u.matrix_col1.y * ly + u.matrix_col1.z;
|
|
75
|
+
|
|
76
|
+
let targetW = u.matrix_col0.w;
|
|
77
|
+
let targetH = u.matrix_col1.w;
|
|
78
|
+
|
|
79
|
+
let x_clip = (tx / targetW) * 2.0 - 1.0;
|
|
80
|
+
let y_clip = 1.0 - (ty / targetH) * 2.0;
|
|
81
|
+
|
|
82
|
+
let u_coord = f32(gridC) / f32(cellsCol);
|
|
83
|
+
let v_coord = f32(gridR) / f32(cellsRow);
|
|
84
|
+
|
|
85
|
+
return VSOut(vec4<f32>(x_clip, y_clip, 0.0, 1.0), vec2<f32>(u_coord, v_coord));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@fragment fn fs(in : VSOut) -> @location(0) vec4<f32> {
|
|
89
|
+
let color = textureSampleLevel(tex, samp, in.uv, 0.0);
|
|
90
|
+
return color;
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
interface DeviceMeshWarpResources {
|
|
95
|
+
warpPipeline: GPURenderPipeline;
|
|
96
|
+
warpUniformLayout: GPUBindGroupLayout;
|
|
97
|
+
warpTextureLayout: GPUBindGroupLayout;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const deviceResourceCache = new WeakMap<GPUDevice, DeviceMeshWarpResources>();
|
|
101
|
+
|
|
102
|
+
function getMeshWarpResources(device: GPUDevice, format: GPUTextureFormat) {
|
|
103
|
+
let res = deviceResourceCache.get(device);
|
|
104
|
+
if (!res) {
|
|
105
|
+
const warpUniformLayout = device.createBindGroupLayout({
|
|
106
|
+
entries: [
|
|
107
|
+
{
|
|
108
|
+
binding: 0,
|
|
109
|
+
visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
|
|
110
|
+
buffer: { type: "uniform" },
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const warpTextureLayout = device.createBindGroupLayout({
|
|
116
|
+
entries: [
|
|
117
|
+
{
|
|
118
|
+
binding: 0,
|
|
119
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
120
|
+
texture: { sampleType: "float" },
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
binding: 1,
|
|
124
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
125
|
+
sampler: { type: "filtering" },
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const module = device.createShaderModule({
|
|
131
|
+
label: "mesh_warp.wgsl",
|
|
132
|
+
code: meshWarpWgsl,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const warpPipeline = device.createRenderPipeline({
|
|
136
|
+
label: "MeshWarpPipeline",
|
|
137
|
+
layout: device.createPipelineLayout({
|
|
138
|
+
bindGroupLayouts: [warpUniformLayout, warpTextureLayout],
|
|
139
|
+
}),
|
|
140
|
+
vertex: {
|
|
141
|
+
module,
|
|
142
|
+
entryPoint: "vs",
|
|
143
|
+
},
|
|
144
|
+
fragment: {
|
|
145
|
+
module,
|
|
146
|
+
entryPoint: "fs",
|
|
147
|
+
targets: [
|
|
148
|
+
{
|
|
149
|
+
format,
|
|
150
|
+
blend: {
|
|
151
|
+
color: {
|
|
152
|
+
srcFactor: "src-alpha",
|
|
153
|
+
dstFactor: "one-minus-src-alpha",
|
|
154
|
+
operation: "add",
|
|
155
|
+
},
|
|
156
|
+
alpha: {
|
|
157
|
+
srcFactor: "one",
|
|
158
|
+
dstFactor: "one-minus-src-alpha",
|
|
159
|
+
operation: "add",
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
primitive: {
|
|
166
|
+
topology: "triangle-list",
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
res = { warpPipeline, warpUniformLayout, warpTextureLayout };
|
|
171
|
+
deviceResourceCache.set(device, res);
|
|
172
|
+
}
|
|
173
|
+
return res;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const MeshWarpWebGPURenderer: WebGPUNodeRenderer = async (args) => {
|
|
177
|
+
const {
|
|
178
|
+
ctx,
|
|
179
|
+
props,
|
|
180
|
+
drawChild,
|
|
181
|
+
targetTexture,
|
|
182
|
+
targetView,
|
|
183
|
+
targetWidth,
|
|
184
|
+
targetHeight,
|
|
185
|
+
encoder,
|
|
186
|
+
} = args;
|
|
187
|
+
const { virtualMedia } = props;
|
|
188
|
+
const op = virtualMedia?.operation as any;
|
|
189
|
+
if (!op || op.op !== "MeshWarp") return;
|
|
190
|
+
|
|
191
|
+
const childMedia = virtualMedia.children?.[0];
|
|
192
|
+
if (!childMedia) return;
|
|
193
|
+
|
|
194
|
+
const sourceWidth =
|
|
195
|
+
op.originalWidth ??
|
|
196
|
+
childMedia.metadata?.width ??
|
|
197
|
+
props.containerWidth ??
|
|
198
|
+
targetWidth;
|
|
199
|
+
const sourceHeight =
|
|
200
|
+
op.originalHeight ??
|
|
201
|
+
childMedia.metadata?.height ??
|
|
202
|
+
props.containerHeight ??
|
|
203
|
+
targetHeight;
|
|
204
|
+
|
|
205
|
+
// End incoming pass to avoid conflicts
|
|
206
|
+
args.pass.end();
|
|
207
|
+
|
|
208
|
+
// 1. Render child into a temporary offscreen texture at its native size
|
|
209
|
+
const childTex = ctx.renderer.getTemporaryTexture(sourceWidth, sourceHeight, [
|
|
210
|
+
...(props.excludeTextures || []),
|
|
211
|
+
targetTexture,
|
|
212
|
+
]);
|
|
213
|
+
const childView = childTex.createView();
|
|
214
|
+
|
|
215
|
+
const clearPass = ctx.renderer.beginFrame(
|
|
216
|
+
encoder,
|
|
217
|
+
childView,
|
|
218
|
+
{ r: 0, g: 0, b: 0, a: 0 },
|
|
219
|
+
sourceWidth,
|
|
220
|
+
sourceHeight,
|
|
221
|
+
"clear",
|
|
222
|
+
);
|
|
223
|
+
clearPass.end();
|
|
224
|
+
|
|
225
|
+
ctx.renderer.pushScissor({
|
|
226
|
+
x: 0,
|
|
227
|
+
y: 0,
|
|
228
|
+
width: sourceWidth,
|
|
229
|
+
height: sourceHeight,
|
|
230
|
+
});
|
|
231
|
+
ctx.renderer.pushIdentity();
|
|
232
|
+
|
|
233
|
+
await drawChild(
|
|
234
|
+
childMedia,
|
|
235
|
+
{
|
|
236
|
+
...props,
|
|
237
|
+
containerWidth: sourceWidth,
|
|
238
|
+
containerHeight: sourceHeight,
|
|
239
|
+
},
|
|
240
|
+
childView,
|
|
241
|
+
childTex,
|
|
242
|
+
sourceWidth,
|
|
243
|
+
sourceHeight,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
ctx.renderer.popTransform();
|
|
247
|
+
ctx.renderer.popScissor();
|
|
248
|
+
|
|
249
|
+
// 2. Setup warp rendering to targetView
|
|
250
|
+
const cols = Number(op.cols) || 3;
|
|
251
|
+
const rows = Number(op.rows) || 3;
|
|
252
|
+
const points = op.points || [];
|
|
253
|
+
|
|
254
|
+
const finalPoints =
|
|
255
|
+
points.length === cols * rows ? points : createUniformGrid(cols, rows);
|
|
256
|
+
|
|
257
|
+
// Setup uniforms: gridSize (vec2), layerSize (vec2), matrix_col0 (vec4), matrix_col1 (vec4), then 144 points
|
|
258
|
+
const maxPoints = 144;
|
|
259
|
+
const uniformData = new Float32Array(12 + maxPoints * 4);
|
|
260
|
+
uniformData[0] = cols;
|
|
261
|
+
uniformData[1] = rows;
|
|
262
|
+
uniformData[2] = props.containerWidth ?? sourceWidth;
|
|
263
|
+
uniformData[3] = props.containerHeight ?? sourceHeight;
|
|
264
|
+
|
|
265
|
+
const matrix = ctx.renderer.getCurrentTransform();
|
|
266
|
+
uniformData[4] = matrix.a;
|
|
267
|
+
uniformData[5] = matrix.c;
|
|
268
|
+
uniformData[6] = matrix.e;
|
|
269
|
+
uniformData[7] = targetWidth;
|
|
270
|
+
|
|
271
|
+
uniformData[8] = matrix.b;
|
|
272
|
+
uniformData[9] = matrix.d;
|
|
273
|
+
uniformData[10] = matrix.f;
|
|
274
|
+
uniformData[11] = targetHeight;
|
|
275
|
+
|
|
276
|
+
for (let i = 0; i < maxPoints; i++) {
|
|
277
|
+
const pt = finalPoints[i] || { x: 0, y: 0 };
|
|
278
|
+
uniformData[12 + i * 4] = pt.x;
|
|
279
|
+
uniformData[12 + i * 4 + 1] = pt.y;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const {
|
|
283
|
+
warpPipeline: pipeline,
|
|
284
|
+
warpUniformLayout: uLayout,
|
|
285
|
+
warpTextureLayout: tLayout,
|
|
286
|
+
} = getMeshWarpResources(ctx.device, ctx.renderer.format);
|
|
287
|
+
|
|
288
|
+
const sampler = ctx.renderer.samplerCache.getSampler(ctx.device);
|
|
289
|
+
const uniformBuffer = ctx.renderer.getTemporaryBuffer(uniformData);
|
|
290
|
+
|
|
291
|
+
const uniformBindGroup = ctx.device.createBindGroup({
|
|
292
|
+
layout: uLayout!,
|
|
293
|
+
entries: [{ binding: 0, resource: { buffer: uniformBuffer } }],
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const textureBindGroup = ctx.renderer.bindGroupCache.getBindGroup(
|
|
297
|
+
ctx.device,
|
|
298
|
+
tLayout!,
|
|
299
|
+
childTex,
|
|
300
|
+
sampler,
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
const outPass = ctx.renderer.beginFrame(
|
|
304
|
+
encoder,
|
|
305
|
+
targetView,
|
|
306
|
+
{ r: 0, g: 0, b: 0, a: 0 },
|
|
307
|
+
targetWidth,
|
|
308
|
+
targetHeight,
|
|
309
|
+
"load",
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
outPass.setPipeline(pipeline!);
|
|
313
|
+
outPass.setBindGroup(0, uniformBindGroup);
|
|
314
|
+
outPass.setBindGroup(1, textureBindGroup);
|
|
315
|
+
|
|
316
|
+
const cellCount = (cols - 1) * (rows - 1);
|
|
317
|
+
const vertexCount = cellCount * 6;
|
|
318
|
+
outPass.draw(vertexCount);
|
|
319
|
+
|
|
320
|
+
args.pass = outPass;
|
|
321
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createOutputItemSchema,
|
|
3
|
+
SingleOutputGenericSchema,
|
|
4
|
+
VirtualMediaDataSchema,
|
|
5
|
+
} from "@framefields/core";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
export const MeshWarpNodeConfigSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
cols: z.number().int().min(2).max(12).default(3),
|
|
11
|
+
rows: z.number().int().min(2).max(12).default(3),
|
|
12
|
+
points: z
|
|
13
|
+
.array(
|
|
14
|
+
z.object({
|
|
15
|
+
x: z.number().min(0).max(100),
|
|
16
|
+
y: z.number().min(0).max(100),
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
.max(144)
|
|
20
|
+
.optional(),
|
|
21
|
+
})
|
|
22
|
+
.strict()
|
|
23
|
+
.superRefine((data, ctx) => {
|
|
24
|
+
if (data.points && data.points.length > 0) {
|
|
25
|
+
const expected = data.cols * data.rows;
|
|
26
|
+
if (data.points.length !== expected) {
|
|
27
|
+
ctx.addIssue({
|
|
28
|
+
code: z.ZodIssueCode.custom,
|
|
29
|
+
path: ["points"],
|
|
30
|
+
message: `points array must have exactly ${expected} coordinates (cols * rows), got ${data.points.length}`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export type MeshWarpNodeConfig = z.infer<typeof MeshWarpNodeConfigSchema>;
|
|
37
|
+
|
|
38
|
+
export const MeshWarpOperationSchema = MeshWarpNodeConfigSchema.extend({
|
|
39
|
+
op: z.literal("MeshWarp"),
|
|
40
|
+
metadata: z.any().optional(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export type MeshWarpOperation = z.infer<typeof MeshWarpOperationSchema>;
|
|
44
|
+
|
|
45
|
+
export const MeshWarpResultSchema = SingleOutputGenericSchema(
|
|
46
|
+
z.union([
|
|
47
|
+
createOutputItemSchema(z.literal("Video"), VirtualMediaDataSchema),
|
|
48
|
+
createOutputItemSchema(z.literal("Image"), VirtualMediaDataSchema),
|
|
49
|
+
createOutputItemSchema(z.literal("SVG"), VirtualMediaDataSchema),
|
|
50
|
+
createOutputItemSchema(z.literal("GIF"), VirtualMediaDataSchema),
|
|
51
|
+
]),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export type MeshWarpResult = z.infer<typeof MeshWarpResultSchema>;
|
|
55
|
+
|
|
56
|
+
export const WARP_OUTPUT_TYPE_MAP: Record<
|
|
57
|
+
string,
|
|
58
|
+
"Image" | "Video" | "GIF" | "SVG"
|
|
59
|
+
> = {
|
|
60
|
+
Video: "Video",
|
|
61
|
+
Lottie: "Video",
|
|
62
|
+
GIF: "GIF",
|
|
63
|
+
Image: "Image",
|
|
64
|
+
SVG: "Image",
|
|
65
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export function createUniformGrid(cols: number, rows: number) {
|
|
2
|
+
const points: { x: number; y: number }[] = [];
|
|
3
|
+
for (let r = 0; r < rows; r++) {
|
|
4
|
+
const y = (r / (rows - 1)) * 100;
|
|
5
|
+
for (let c = 0; c < cols; c++) {
|
|
6
|
+
const x = (c / (cols - 1)) * 100;
|
|
7
|
+
points.push({ x, y });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return points;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function interpolateGridPoint(
|
|
14
|
+
u: number,
|
|
15
|
+
v: number,
|
|
16
|
+
oldPoints: { x: number; y: number }[],
|
|
17
|
+
oldCols: number,
|
|
18
|
+
oldRows: number,
|
|
19
|
+
) {
|
|
20
|
+
const px = u * (oldCols - 1);
|
|
21
|
+
const py = v * (oldRows - 1);
|
|
22
|
+
|
|
23
|
+
const x0 = Math.floor(px);
|
|
24
|
+
const x1 = Math.min(oldCols - 1, x0 + 1);
|
|
25
|
+
const y0 = Math.floor(py);
|
|
26
|
+
const y1 = Math.min(oldRows - 1, y0 + 1);
|
|
27
|
+
|
|
28
|
+
const tx = px - x0;
|
|
29
|
+
const ty = py - y0;
|
|
30
|
+
|
|
31
|
+
const p00 = oldPoints[y0 * oldCols + x0];
|
|
32
|
+
const p10 = oldPoints[y0 * oldCols + x1];
|
|
33
|
+
const p01 = oldPoints[y1 * oldCols + x0];
|
|
34
|
+
const p11 = oldPoints[y1 * oldCols + x1];
|
|
35
|
+
|
|
36
|
+
if (!p00 || !p10 || !p01 || !p11) {
|
|
37
|
+
return { x: u * 100, y: v * 100 };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const x =
|
|
41
|
+
(1 - tx) * (1 - ty) * p00.x +
|
|
42
|
+
tx * (1 - ty) * p10.x +
|
|
43
|
+
(1 - tx) * ty * p01.x +
|
|
44
|
+
tx * ty * p11.x;
|
|
45
|
+
|
|
46
|
+
const y =
|
|
47
|
+
(1 - tx) * (1 - ty) * p00.y +
|
|
48
|
+
tx * (1 - ty) * p10.y +
|
|
49
|
+
(1 - tx) * ty * p01.y +
|
|
50
|
+
tx * ty * p11.y;
|
|
51
|
+
|
|
52
|
+
return { x, y };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function resizeGrid(
|
|
56
|
+
oldPoints: { x: number; y: number }[] | undefined | null,
|
|
57
|
+
oldCols: number,
|
|
58
|
+
oldRows: number,
|
|
59
|
+
newCols: number,
|
|
60
|
+
newRows: number,
|
|
61
|
+
) {
|
|
62
|
+
if (!oldPoints || oldPoints.length !== oldCols * oldRows) {
|
|
63
|
+
return createUniformGrid(newCols, newRows);
|
|
64
|
+
}
|
|
65
|
+
const points: { x: number; y: number }[] = [];
|
|
66
|
+
for (let r = 0; r < newRows; r++) {
|
|
67
|
+
const v = r / (newRows - 1);
|
|
68
|
+
for (let c = 0; c < newCols; c++) {
|
|
69
|
+
const u = c / (newCols - 1);
|
|
70
|
+
points.push(interpolateGridPoint(u, v, oldPoints, oldCols, oldRows));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return points;
|
|
74
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@framefields/tsconfig/node-library.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": ["./src/*"]
|
|
7
|
+
},
|
|
8
|
+
"lib": ["DOM"],
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"emitDecoratorMetadata": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src"]
|
|
13
|
+
}
|
package/tsdown.config.ts
ADDED
package/README.md
DELETED