@driftengine/capture 4.0.0
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/LICENSE +202 -0
- package/NOTICE +29 -0
- package/README.md +68 -0
- package/dist/browserFrames.d.ts +31 -0
- package/dist/browserFrames.js +105 -0
- package/dist/collide.d.ts +59 -0
- package/dist/collide.js +92 -0
- package/dist/decimate.d.ts +42 -0
- package/dist/decimate.js +439 -0
- package/dist/delight.d.ts +42 -0
- package/dist/delight.js +351 -0
- package/dist/delightScene.d.ts +37 -0
- package/dist/delightScene.js +183 -0
- package/dist/depth.d.ts +44 -0
- package/dist/depth.js +53 -0
- package/dist/features.d.ts +33 -0
- package/dist/features.js +260 -0
- package/dist/frames.d.ts +47 -0
- package/dist/frames.js +87 -0
- package/dist/fusion.d.ts +77 -0
- package/dist/fusion.js +152 -0
- package/dist/gaussians/adam.d.ts +57 -0
- package/dist/gaussians/adam.js +88 -0
- package/dist/gaussians/depth.d.ts +8 -0
- package/dist/gaussians/depth.js +73 -0
- package/dist/gaussians/gradients.d.ts +36 -0
- package/dist/gaussians/gradients.js +228 -0
- package/dist/gaussians/harmonics.d.ts +46 -0
- package/dist/gaussians/harmonics.js +99 -0
- package/dist/gaussians/optimise.d.ts +50 -0
- package/dist/gaussians/optimise.js +125 -0
- package/dist/gaussians/parameters.d.ts +35 -0
- package/dist/gaussians/parameters.js +165 -0
- package/dist/gaussians/project.d.ts +72 -0
- package/dist/gaussians/project.js +137 -0
- package/dist/gaussians/projectGradient.d.ts +15 -0
- package/dist/gaussians/projectGradient.js +213 -0
- package/dist/gaussians/rasterise.d.ts +13 -0
- package/dist/gaussians/rasterise.js +65 -0
- package/dist/gaussians/refine.d.ts +36 -0
- package/dist/gaussians/refine.js +136 -0
- package/dist/gaussians/similarity.d.ts +25 -0
- package/dist/gaussians/similarity.js +80 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +96 -0
- package/dist/marching.d.ts +38 -0
- package/dist/marching.js +258 -0
- package/dist/masks.d.ts +59 -0
- package/dist/masks.js +165 -0
- package/dist/math/dense.d.ts +68 -0
- package/dist/math/dense.js +294 -0
- package/dist/math/schur.d.ts +23 -0
- package/dist/math/schur.js +140 -0
- package/dist/models/batchNorm.d.ts +17 -0
- package/dist/models/batchNorm.js +24 -0
- package/dist/models/clipTokenizer.d.ts +40 -0
- package/dist/models/clipTokenizer.js +122 -0
- package/dist/models/clipTower.d.ts +27 -0
- package/dist/models/clipTower.js +45 -0
- package/dist/models/depthAnything2.d.ts +38 -0
- package/dist/models/depthAnything2.js +163 -0
- package/dist/models/depthAnything3.d.ts +26 -0
- package/dist/models/depthAnything3.js +171 -0
- package/dist/models/dualDpt.d.ts +19 -0
- package/dist/models/dualDpt.js +138 -0
- package/dist/models/hiera.d.ts +49 -0
- package/dist/models/hiera.js +120 -0
- package/dist/models/hieraAttention.d.ts +16 -0
- package/dist/models/hieraAttention.js +68 -0
- package/dist/models/miniature.d.ts +36 -0
- package/dist/models/miniature.js +216 -0
- package/dist/models/mobileSam.d.ts +41 -0
- package/dist/models/mobileSam.js +88 -0
- package/dist/models/owlv2.d.ts +49 -0
- package/dist/models/owlv2.js +131 -0
- package/dist/models/owlv2Detect.d.ts +25 -0
- package/dist/models/owlv2Detect.js +80 -0
- package/dist/models/owlv2Miniature.d.ts +27 -0
- package/dist/models/owlv2Miniature.js +87 -0
- package/dist/models/rope.d.ts +23 -0
- package/dist/models/rope.js +84 -0
- package/dist/models/sam21.d.ts +45 -0
- package/dist/models/sam21.js +126 -0
- package/dist/models/sam21Miniature.d.ts +37 -0
- package/dist/models/sam21Miniature.js +194 -0
- package/dist/models/sam21Video.d.ts +30 -0
- package/dist/models/sam21Video.js +101 -0
- package/dist/models/sam2Choice.d.ts +19 -0
- package/dist/models/sam2Choice.js +55 -0
- package/dist/models/sam2Decoder.d.ts +36 -0
- package/dist/models/sam2Decoder.js +108 -0
- package/dist/models/sam2Memories.d.ts +54 -0
- package/dist/models/sam2Memories.js +93 -0
- package/dist/models/sam2Memory.d.ts +30 -0
- package/dist/models/sam2Memory.js +136 -0
- package/dist/models/sam2Positions.d.ts +24 -0
- package/dist/models/sam2Positions.js +94 -0
- package/dist/models/sam2Tracker.d.ts +69 -0
- package/dist/models/sam2Tracker.js +172 -0
- package/dist/models/samDecoder.d.ts +45 -0
- package/dist/models/samDecoder.js +96 -0
- package/dist/models/samMiniature.d.ts +43 -0
- package/dist/models/samMiniature.js +161 -0
- package/dist/models/samPrompt.d.ts +57 -0
- package/dist/models/samPrompt.js +160 -0
- package/dist/models/seeded.d.ts +16 -0
- package/dist/models/seeded.js +48 -0
- package/dist/models/tinyVit.d.ts +38 -0
- package/dist/models/tinyVit.js +82 -0
- package/dist/models/twoWay.d.ts +46 -0
- package/dist/models/twoWay.js +67 -0
- package/dist/models/vit.d.ts +45 -0
- package/dist/models/vit.js +157 -0
- package/dist/models/windowAttention.d.ts +25 -0
- package/dist/models/windowAttention.js +104 -0
- package/dist/poses.d.ts +31 -0
- package/dist/poses.js +750 -0
- package/dist/prepare.d.ts +30 -0
- package/dist/prepare.js +238 -0
- package/dist/propose.d.ts +36 -0
- package/dist/propose.js +63 -0
- package/dist/resample.d.ts +39 -0
- package/dist/resample.js +165 -0
- package/dist/run.d.ts +3 -0
- package/dist/run.js +1 -0
- package/dist/scene.d.ts +104 -0
- package/dist/scene.js +109 -0
- package/dist/segment.d.ts +40 -0
- package/dist/segment.js +184 -0
- package/dist/testScene.d.ts +55 -0
- package/dist/testScene.js +214 -0
- package/dist/twoView.d.ts +22 -0
- package/dist/twoView.js +435 -0
- package/package.json +63 -0
- package/src/browserFrames.ts +145 -0
- package/src/collide.ts +128 -0
- package/src/decimate.ts +510 -0
- package/src/delight.ts +427 -0
- package/src/delightScene.ts +249 -0
- package/src/depth.ts +100 -0
- package/src/features.ts +302 -0
- package/src/frames.ts +111 -0
- package/src/fusion.ts +229 -0
- package/src/gaussians/adam.ts +131 -0
- package/src/gaussians/depth.ts +87 -0
- package/src/gaussians/gradients.ts +285 -0
- package/src/gaussians/harmonics.ts +122 -0
- package/src/gaussians/optimise.ts +191 -0
- package/src/gaussians/parameters.ts +186 -0
- package/src/gaussians/project.ts +207 -0
- package/src/gaussians/projectGradient.ts +234 -0
- package/src/gaussians/rasterise.ts +81 -0
- package/src/gaussians/refine.ts +176 -0
- package/src/gaussians/similarity.ts +87 -0
- package/src/index.ts +225 -0
- package/src/marching.ts +358 -0
- package/src/masks.ts +201 -0
- package/src/math/dense.ts +317 -0
- package/src/math/schur.ts +167 -0
- package/src/models/batchNorm.ts +57 -0
- package/src/models/clipTokenizer.ts +129 -0
- package/src/models/clipTower.ts +87 -0
- package/src/models/depthAnything2.ts +276 -0
- package/src/models/depthAnything3.ts +229 -0
- package/src/models/dualDpt.ts +233 -0
- package/src/models/hiera.ts +231 -0
- package/src/models/hieraAttention.ts +121 -0
- package/src/models/miniature.ts +241 -0
- package/src/models/mobileSam.ts +135 -0
- package/src/models/owlv2.ts +190 -0
- package/src/models/owlv2Detect.ts +116 -0
- package/src/models/owlv2Miniature.ts +108 -0
- package/src/models/rope.ts +111 -0
- package/src/models/sam21.ts +182 -0
- package/src/models/sam21Miniature.ts +225 -0
- package/src/models/sam21Video.ts +154 -0
- package/src/models/sam2Choice.ts +62 -0
- package/src/models/sam2Decoder.ts +218 -0
- package/src/models/sam2Memories.ts +165 -0
- package/src/models/sam2Memory.ts +247 -0
- package/src/models/sam2Positions.ts +106 -0
- package/src/models/sam2Tracker.ts +300 -0
- package/src/models/samDecoder.ts +225 -0
- package/src/models/samMiniature.ts +190 -0
- package/src/models/samPrompt.ts +227 -0
- package/src/models/seeded.ts +50 -0
- package/src/models/tinyVit.ts +178 -0
- package/src/models/twoWay.ts +122 -0
- package/src/models/vit.ts +265 -0
- package/src/models/windowAttention.ts +155 -0
- package/src/poses.ts +894 -0
- package/src/prepare.ts +306 -0
- package/src/propose.ts +96 -0
- package/src/resample.ts +197 -0
- package/src/run.ts +7 -0
- package/src/scene.ts +141 -0
- package/src/segment.ts +220 -0
- package/src/testScene.ts +283 -0
- package/src/twoView.ts +536 -0
package/LICENSE
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 Drift Technologies
|
|
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/NOTICE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
DriftEngine
|
|
2
|
+
Copyright 2026 Drift Technologies
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Drift Technologies
|
|
5
|
+
(https://github.com/drftrun/driftengine).
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0. Section 4(d) of that licence
|
|
8
|
+
requires this NOTICE to be reproduced in any derivative work you distribute,
|
|
9
|
+
in the source, the documentation, or a display generated by the work.
|
|
10
|
+
|
|
11
|
+
Models run by DriftCapture
|
|
12
|
+
--------------------------
|
|
13
|
+
DriftCapture runs the models below. Their weights are not in this repository
|
|
14
|
+
and are not distributed with it: tools/capture-weights/ fetches each at the
|
|
15
|
+
revision its manifest pins, verifies it, and converts it, and a game that
|
|
16
|
+
ships one ships it under that model's own licence. Each model's definition in
|
|
17
|
+
this engine is written from its project's published code.
|
|
18
|
+
|
|
19
|
+
- Depth Anything 3 Small and Depth Anything 3 Base. Apache License 2.0.
|
|
20
|
+
Copyright (c) 2025 ByteDance Ltd. and/or its affiliates.
|
|
21
|
+
- Depth Anything V2 Small. Apache License 2.0. The University of Hong Kong
|
|
22
|
+
and TikTok; converted to the Transformers layout by The HuggingFace Team.
|
|
23
|
+
- MobileSAM. Apache License 2.0. Its image encoder is TinyViT, Copyright (c)
|
|
24
|
+
2022 Microsoft; its prompt encoder and mask decoder are Segment Anything's,
|
|
25
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
26
|
+
- SAM 2.1 tiny. Apache License 2.0. Copyright (c) Meta Platforms, Inc. and
|
|
27
|
+
affiliates.
|
|
28
|
+
- OWLv2 base patch16. Apache License 2.0. Copyright 2023 Google AI and The
|
|
29
|
+
HuggingFace Team.
|
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# `@driftengine/capture`
|
|
2
|
+
|
|
3
|
+
A video to a playable scene, on the player's own device — no service, no account, and a runtime
|
|
4
|
+
that never fetches.
|
|
5
|
+
|
|
6
|
+
**66,373 bytes gzipped**, measured by `scripts/size-gate.test.mjs` against
|
|
7
|
+
`scripts/fixtures/size/capture-only.ts`. Optional: nothing in `@driftengine/core` imports it.
|
|
8
|
+
|
|
9
|
+
## What is here so far
|
|
10
|
+
|
|
11
|
+
The models a capture runs, each written as a **definition**: a function of a model's weights that
|
|
12
|
+
`@driftengine/texture`'s `graphFromWeights` builds into a graph the engine's one neural runtime runs,
|
|
13
|
+
on the CPU as a reference or on the device through `@driftengine/core`'s `createGraphRunner`.
|
|
14
|
+
|
|
15
|
+
| Export | What it is |
|
|
16
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `depthAnything3(config, views, h, w)` | Depth Anything 3 at `views` images of `h × w` pixels: logits per view and a pose encoding for all of them |
|
|
18
|
+
| `DEPTH_ANYTHING_3.small`, `.base` | The two accepted sizes, from each checkpoint's configuration at its pinned revision |
|
|
19
|
+
| `depthAnything2(config, h, w)`, `DEPTH_ANYTHING_2_SMALL` | Depth Anything V2 Small, the lighter fallback: relative inverse depth from one view, in Transformers' layout |
|
|
20
|
+
| `decodeDepth`, `decodeCamera` | The logits as depth and a confidence of at least one; a pose encoding as world-to-camera and a pinhole |
|
|
21
|
+
| `mobileSamEncoder(config)`, `mobileSamDecoder(config, tokens, refine?)`, `MOBILE_SAM` | MobileSAM in two graphs: an image to its embedding once, and a prompt's tokens — and the last mask, to refine — to four masks and their predicted quality |
|
|
22
|
+
| `samPromptTokens`, `samTokenCount`, `samMasksToImage`, `stabilityScore` | A prompt of points and a box as the decoder's tokens; the masks brought to the original image; the upstream's stability score |
|
|
23
|
+
| `sam21Encoder(config)`, `sam21Decoder(config, tokens, options)`, `Sam21Tracker`, `SAM_21_TINY` | SAM 2.1: masks from a point or a box on an image, and objects tracked through a video by a memory of the frames before them, the loop on the host and its networks as graphs |
|
|
24
|
+
| `owlv2Image(config)`, `owlv2Text(config, queries)`, `owlv2Logits`, `owlv2Detections`, `OWLV2_BASE` | OWLv2: an image's patches once, a set of text queries once, joined on the host into a logit a patch and query and those into boxes above a threshold |
|
|
25
|
+
| `clipTokenizer(merges)`, `owlv2Tokens` | CLIP's byte-level tokenizer from the merges a converted file carries, and queries padded as the text graph takes them |
|
|
26
|
+
| `eachFrame(source, visit)`, `selectFrames(source, { budget, every? })`, `browserFrameSource(clip)` | A clip through the host's own `FrameSource`, read one frame at a time; the frames a capture keeps, spaced by equal motion; a browser's video element behind one |
|
|
27
|
+
| `prepareDepthFrame`, `prepareSamFrame`, `prepareSam2Frame`, `prepareOwlv2Frame` | A frame as each model's own upstream prepares it, down to the resize each library uses |
|
|
28
|
+
| `createDepthEstimator(config, weights, run)` | A clip's frames to depth, confidence and a camera a view, a graph kept per prepared size |
|
|
29
|
+
| `svd3`, `svdN`, `symmetricEigen`, `cholesky`, `levenbergMarquardt`, `schurSolve` | The decompositions structure from motion needs, in double precision, each held to its own identity |
|
|
30
|
+
| `detectFeatures`, `describeFeatures`, `matchFeatures` | Corners, a description of each turned by its own orientation, and the matches between two frames — mutual, and unambiguous from both sides |
|
|
31
|
+
| `relativePose(a, b, count, intrinsics, random, out)`, `triangulate(...)` | The pose between two views by seeded RANSAC over both models, and the points behind the matches; **a pair with no parallax is reported as a turn** rather than fitted with a translation |
|
|
32
|
+
| `renderTestScene(scene, camera, out, depth?)`, `lookAt` | Analytic scenes ray cast on the CPU, with the true depth beside the colour: the fixture every later stage is held to |
|
|
33
|
+
| `estimatePoses(frames, options, out)` | The clip's camera path: tracks, a two-view or depth-model start, every frame placed by what it sees, and a bundle adjustment — with per-pose confidence, **`parallax: false` where the clip only turned**, and a scale that is metric only when a length was given |
|
|
34
|
+
| `optimiseGaussians(targets, poses, options)` | A clip's frames and its camera path fitted into Gaussians, out as `@driftengine/splats`' own `SplatSource`: Adam over six families, scale as a logarithm and opacity as a logit, densified by which Gaussians the frames pull on and pruned by what has faded, with a degree-1 band on request |
|
|
35
|
+
| `rasteriseGaussians(set, camera, out)`, `projectGaussian`, `accumulateGradients`, `imageLoss` | The reference rasteriser the fit descends: the projection `@driftengine/splats`' shader performs, low-pass included, and every analytic gradient behind it — checked against a central difference of itself |
|
|
36
|
+
| `splatColour`, `sh1Basis`, `SH_C1` | The degree-1 band, evaluated exactly as that shader evaluates it, so a capture fitted here is shaded there the same way |
|
|
37
|
+
| `structuralSimilarity(a, b, width, height)` | How alike two pictures are, structure included — what a fit is judged by, where a squared difference is only what it descends |
|
|
38
|
+
| `renderDepth(set, camera, depth, coverage)` | How far away a cloud is, a pixel at a time: each splat's own depth weighted by how much of the pixel it lit, with the coverage beside it — because a depth averaged out of a tenth of a pixel's light is not a measurement |
|
|
39
|
+
| `createVolume(dims, origin, spacing)`, `fuseDepth(views, volume)` | Many views averaged into one truncated signed distance, weighted by how squarely each saw the surface. Space in front of a surface is carved out, space behind it is left alone, and a surface one view saw is kept at the weight one view is worth |
|
|
40
|
+
| `marchVolume(volume, options?)` | That volume's crossing as a mesh, by tetrahedra rather than cubes so it is closed by construction, **facing outwards** — and open where the capture never looked, rather than capped with a surface nobody measured |
|
|
41
|
+
| `decimate(mesh, budget, options?)` | The mesh brought to a triangle budget by quadric-error collapse: a wall flattens, a corner keeps its detail, the border of an open capture is held, and a collapse that would turn a face inside out is refused |
|
|
42
|
+
| `collisionMesh(mesh, options?)` | The drawn mesh cleaned for collision: triangles with no area taken out, because a plane needs a normal, and the vertices nothing uses any more taken with them. What comes back is what `meshShape` takes |
|
|
43
|
+
| `propHulls(mesh, options?)` | A prop as convex hulls, asked for inside `COLL`'s own caps rather than checked against them after the expensive part — a room is a mesh body and a prop is hulls, and the difference is that one can be thrown |
|
|
44
|
+
| `delight(views, mesh, options, out)` | A surface's material, separated from the light it was photographed under: what stays the same across views is the material, what moves is the light, and an intensity jump the colour does not follow is a shadow. **Every vertex carries a confidence**, and the module states plainly what that confidence grades and what it does not — on the synthetic scene a cast shadow that darkens a floor 4.8× in the photographs comes back 2.2× in the albedo |
|
|
45
|
+
| `renderLit(scene, camera, light, out)`, `nearestHit` | The lit fixture those measurements are made against: a triangle mesh, one directional light, a hard shadow ray and a normalised specular lobe — enough to pose the question and no more |
|
|
46
|
+
| `segmentGeometry(mesh, options?)` | The mesh cut into surfaces with no model loaded at all: runs of triangles that share an edge and a plane, largest first. A floor, its walls and the top of a table are findable without knowing what any of them _is_, and that is most of what a scene needs |
|
|
47
|
+
| `liftMasks(views, mesh, labels)`, `promptGrid(width, height, across, down, random)` | A segmentation model's masks voted onto the mesh across every view that saw a triangle, and the seeded lattice it is prompted on — a triangle no view claimed is left unassigned rather than given to its neighbour |
|
|
48
|
+
| `labelMasks(view, detections, queries, overlap?)` | A detector's boxes put names to a segmenter's mask indices, by how far each box and mask agree — the mask's own pixels against the box, so a box drawn around a room does not name every cushion in it. A mask that agrees with nothing keeps no name, and no name is scenery |
|
|
49
|
+
| `proposeEntities(regions, options?)`, `SCENERY_COMPONENTS`, `WALKABLE_COMPONENTS`, `MOVABLE_COMPONENTS` | Each region as a _proposal_, and the word is load-bearing: **a region nobody labelled becomes scenery** — drawn, solid, and doing nothing. The largest surface a character could stand on gets a navigation surface; a named region small enough to shift is offered as movable |
|
|
50
|
+
| `captureFile(scene)`, `proposalScene`, `readProposals`, `PROPOSAL_COMPONENT` | Every stage as one `.drft`: the mesh, its materials and decode program, the cloud, a prop's hulls, the way across the scene and the proposals. **The proposals travel under a component this package declares**, not under a consumer's `transform`, whose field ids belong to that consumer — a capture proposes in its own words and an editor decides what a scene ends up holding |
|
|
51
|
+
| `miniatureCheckpoint`, `miniatureCheckpoint2`, `miniatureImages`, `miniatureSamCheckpoint`, `miniatureSam21Checkpoint`, `miniatureOwlv2Checkpoint` | Seeded miniatures of each layout — every tensor name and shape — for tests and for checking a port of yours |
|
|
52
|
+
|
|
53
|
+
**A definition runs twice.** Once over a checkpoint, when `tools/capture-weights/` converts it, and
|
|
54
|
+
again over the converted file whenever a clip needs the graph at a new size: every device kernel
|
|
55
|
+
bakes its shapes, and a clip's aspect ratio decides the patch grid. Every weight the source holds is
|
|
56
|
+
read or set aside by name, so a forgotten bias is refused rather than run.
|
|
57
|
+
|
|
58
|
+
**Each model answers as its upstream's own code does.** The tests hold each definition to numbers
|
|
59
|
+
the upstream's modules wrote for its miniature at the manifest's pinned revision — Depth Anything 3's
|
|
60
|
+
own repository, Transformers for V2, SAM 2.1 and OWLv2, and MobileSAM's own repository — within a few parts in a
|
|
61
|
+
million;
|
|
62
|
+
`tools/capture-weights/reference/` is the hand-run oracle that produced them.
|
|
63
|
+
|
|
64
|
+
## Weights
|
|
65
|
+
|
|
66
|
+
None ship with this package. `tools/capture-weights/manifest.json` pins each accepted model to a
|
|
67
|
+
commit and a SHA-256, and `docs/SHIPPING.md` §12 says what a game ships with one: the converted file,
|
|
68
|
+
the model's licence, and its attribution, which `NOTICE` carries too.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A clip in a browser as a `FrameSource`: a video element decoded into a canvas, a frame at a time.
|
|
3
|
+
*
|
|
4
|
+
* **A declared browser module** — a native host writes its own source over its own decoder, which is
|
|
5
|
+
* the whole point of the seam. Nothing else in this package touches a DOM.
|
|
6
|
+
*
|
|
7
|
+
* **Why a video element rather than WebCodecs.** `VideoDecoder` takes encoded chunks and a browser
|
|
8
|
+
* ships no demuxer to make them from an MP4, so a WebCodecs source means a demuxing dependency in a
|
|
9
|
+
* package whose bar for one is high. A video element demuxes, decodes and seeks with nothing added,
|
|
10
|
+
* and `drawImage` into a 2D canvas is how its frame becomes bytes. **What it gives up**: a frame is
|
|
11
|
+
* addressed by time rather than by its place in the stream — the middle of frame `index` at the
|
|
12
|
+
* clip's rate — so a clip of variable frame rate answers the frame covering that instant rather
|
|
13
|
+
* than the `index`-th one. What would make that wrong is a capture that needs a particular frame
|
|
14
|
+
* rather than a moment; nothing here does, since frames are chosen by motion.
|
|
15
|
+
*
|
|
16
|
+
* **The rate is measured, not assumed**, from the first frames the decoder presents, and falls back
|
|
17
|
+
* to the caller's `frameRate` where `requestVideoFrameCallback` is absent.
|
|
18
|
+
*/
|
|
19
|
+
import type { FrameSource } from './frames.ts';
|
|
20
|
+
/** A browser's clip, and how to let it go. */
|
|
21
|
+
export interface BrowserClip extends FrameSource {
|
|
22
|
+
/** Releases the element and the object URL; the source answers nothing afterwards. */
|
|
23
|
+
close(): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The clip's frames, addressed at the clip's rate. `frameRate` is the fallback where the browser
|
|
27
|
+
* cannot say what the rate is.
|
|
28
|
+
*/
|
|
29
|
+
export declare function browserFrameSource(clip: Blob, options?: {
|
|
30
|
+
readonly frameRate?: number;
|
|
31
|
+
}): Promise<BrowserClip>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const once = (video, event) => new Promise((resolve, reject) => {
|
|
2
|
+
const done = () => {
|
|
3
|
+
video.removeEventListener(event, done);
|
|
4
|
+
video.removeEventListener('error', failed);
|
|
5
|
+
resolve();
|
|
6
|
+
};
|
|
7
|
+
const failed = () => {
|
|
8
|
+
video.removeEventListener(event, done);
|
|
9
|
+
video.removeEventListener('error', failed);
|
|
10
|
+
reject(new Error(`the clip could not be read: ${video.error?.message ?? 'no reason given'}`));
|
|
11
|
+
};
|
|
12
|
+
video.addEventListener(event, done);
|
|
13
|
+
video.addEventListener('error', failed);
|
|
14
|
+
});
|
|
15
|
+
/** The rate the decoder presents frames at, from two it presents, or null where it cannot say. */
|
|
16
|
+
async function measuredRate(video) {
|
|
17
|
+
if (typeof video.requestVideoFrameCallback !== 'function')
|
|
18
|
+
return null;
|
|
19
|
+
const times = [];
|
|
20
|
+
await new Promise((resolve) => {
|
|
21
|
+
const take = (_now, metadata) => {
|
|
22
|
+
times.push(metadata.mediaTime);
|
|
23
|
+
if (times.length >= 3)
|
|
24
|
+
resolve();
|
|
25
|
+
else
|
|
26
|
+
video.requestVideoFrameCallback?.(take);
|
|
27
|
+
};
|
|
28
|
+
video.requestVideoFrameCallback?.(take);
|
|
29
|
+
void video.play().catch(() => resolve());
|
|
30
|
+
setTimeout(resolve, 2000);
|
|
31
|
+
});
|
|
32
|
+
video.pause();
|
|
33
|
+
const steps = [];
|
|
34
|
+
for (let i = 1; i < times.length; i += 1)
|
|
35
|
+
steps.push(times[i] - times[i - 1]);
|
|
36
|
+
const shortest = Math.min(...steps.filter((step) => step > 0));
|
|
37
|
+
return Number.isFinite(shortest) && shortest > 0 ? 1 / shortest : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The clip's frames, addressed at the clip's rate. `frameRate` is the fallback where the browser
|
|
41
|
+
* cannot say what the rate is.
|
|
42
|
+
*/
|
|
43
|
+
export async function browserFrameSource(clip, options = {}) {
|
|
44
|
+
// platform: browser default — this module is the browser's own `FrameSource`.
|
|
45
|
+
const url = URL.createObjectURL(clip);
|
|
46
|
+
const video = document.createElement('video');
|
|
47
|
+
video.preload = 'auto';
|
|
48
|
+
video.muted = true;
|
|
49
|
+
video.playsInline = true;
|
|
50
|
+
video.src = url;
|
|
51
|
+
await once(video, 'loadedmetadata');
|
|
52
|
+
/*
|
|
53
|
+
* **A container that parses is not a track that decodes**, and the difference is silent.
|
|
54
|
+
*
|
|
55
|
+
* Chrome on Linux plays no HEVC, which is what every recent phone records by default. The file
|
|
56
|
+
* loads, `loadedmetadata` fires, `duration` comes back correct to the millisecond — and
|
|
57
|
+
* `videoWidth` is zero, because nothing decoded. Left alone, the first frame draws a zero-wide
|
|
58
|
+
* image into a zero-wide canvas and dies inside `getImageData` with "the source width is 0",
|
|
59
|
+
* which names neither the clip nor the codec and sends a reader into the canvas code.
|
|
60
|
+
*
|
|
61
|
+
* So it is refused here, by name, with the duration as evidence that the file itself is fine.
|
|
62
|
+
* **What this cannot do is say which codec it was**: the element reports no track it could not
|
|
63
|
+
* decode, so the message names the one that always works rather than guessing at the one that
|
|
64
|
+
* did not.
|
|
65
|
+
*/
|
|
66
|
+
if (video.videoWidth === 0 || video.videoHeight === 0) {
|
|
67
|
+
const seconds = Number.isFinite(video.duration) ? video.duration.toFixed(2) : 'an unknown';
|
|
68
|
+
throw new Error(`this browser cannot decode the clip's video track: it read ${seconds} s of container and ` +
|
|
69
|
+
'no picture. A codec this browser does not have is the usual cause — HEVC on a build ' +
|
|
70
|
+
'without it, which is what most phones record. Convert the clip to H.264 and try again.');
|
|
71
|
+
}
|
|
72
|
+
const rate = (await measuredRate(video)) ?? options.frameRate ?? 30;
|
|
73
|
+
const width = video.videoWidth;
|
|
74
|
+
const height = video.videoHeight;
|
|
75
|
+
const count = Math.max(1, Math.floor(video.duration * rate));
|
|
76
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
77
|
+
const context = canvas.getContext('2d', { willReadFrequently: true });
|
|
78
|
+
if (context === null)
|
|
79
|
+
throw new Error('a clip needs a 2D canvas to become pixels');
|
|
80
|
+
let open = true;
|
|
81
|
+
return {
|
|
82
|
+
frameCount: () => (open ? count : 0),
|
|
83
|
+
async frameAt(index, out) {
|
|
84
|
+
if (!open)
|
|
85
|
+
throw new Error('the clip is closed');
|
|
86
|
+
if (out.length >= width * height * 4) {
|
|
87
|
+
/* The middle of the frame, so rounding cannot land on the boundary either side. */
|
|
88
|
+
const at = Math.min((index + 0.5) / rate, Math.max(0, video.duration - 1 / rate));
|
|
89
|
+
if (Math.abs(video.currentTime - at) > 1e-6) {
|
|
90
|
+
video.currentTime = at;
|
|
91
|
+
await once(video, 'seeked');
|
|
92
|
+
}
|
|
93
|
+
context.drawImage(video, 0, 0, width, height);
|
|
94
|
+
out.set(context.getImageData(0, 0, width, height).data);
|
|
95
|
+
}
|
|
96
|
+
return { width, height };
|
|
97
|
+
},
|
|
98
|
+
close() {
|
|
99
|
+
open = false;
|
|
100
|
+
video.removeAttribute('src');
|
|
101
|
+
video.load();
|
|
102
|
+
URL.revokeObjectURL(url);
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A captured mesh as something to stand on and to put in a file.
|
|
3
|
+
*
|
|
4
|
+
* **The mesh a capture draws and the mesh it collides against are the same triangles and not the
|
|
5
|
+
* same array.** What comes out of `marchVolume` and `decimate` is built for a picture: it carries
|
|
6
|
+
* normals and colours a collision test never reads, and it carries the occasional triangle with no
|
|
7
|
+
* area, which is harmless in a render and is not harmless in a contact — a plane needs a normal,
|
|
8
|
+
* and a triangle with no area has none. So the collision mesh is the drawn one with the arealess
|
|
9
|
+
* triangles taken out and the vertices nothing uses any more taken with them.
|
|
10
|
+
*
|
|
11
|
+
* **A room is a static mesh body and a prop is a set of hulls, and the difference is not size.** A
|
|
12
|
+
* mesh body is exact and cannot move: every triangle is tested as it stands, which is what a floor
|
|
13
|
+
* and a wall want. A convex decomposition is approximate and can be thrown: a hull has a centre of
|
|
14
|
+
* mass, an inertia and a cheap support function, which is what a crate wants. Giving a room hulls
|
|
15
|
+
* would round off its corners; giving a crate a mesh body would leave it unable to be picked up.
|
|
16
|
+
*
|
|
17
|
+
* **The container's caps are the decomposition's brief.** `COLL` holds at most thirty-two hulls of
|
|
18
|
+
* at most sixty-four points, so a decomposition that ignored them would produce a prop that cannot
|
|
19
|
+
* be written — found at the writer, after the expensive part. It is asked for inside them instead.
|
|
20
|
+
*/
|
|
21
|
+
import { type MeshData } from '@driftengine/drft';
|
|
22
|
+
import { type DecomposeOptions } from '@driftengine/physics';
|
|
23
|
+
/** A mesh as `meshShape` takes it, and what had to go for it to be one. */
|
|
24
|
+
export interface CollisionSource {
|
|
25
|
+
readonly positions: Float32Array;
|
|
26
|
+
readonly indices: Uint32Array;
|
|
27
|
+
/** Triangles dropped for having no area to have a plane from. */
|
|
28
|
+
readonly dropped: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CollisionOptions {
|
|
31
|
+
/**
|
|
32
|
+
* The smallest triangle kept, in square metres.
|
|
33
|
+
*
|
|
34
|
+
* **Not zero**, because a triangle of a square micrometre has a plane in the arithmetic and none
|
|
35
|
+
* in any useful sense: its normal is the direction of its own rounding error, and a contact
|
|
36
|
+
* against it points somewhere arbitrary. A square millimetre is far below anything a capture
|
|
37
|
+
* resolves and far above where a cross product stops meaning anything.
|
|
38
|
+
*/
|
|
39
|
+
readonly minimumArea?: number;
|
|
40
|
+
}
|
|
41
|
+
/** `mesh`'s triangles, less the ones with no area, renumbered onto the vertices that remain. */
|
|
42
|
+
export declare function collisionMesh(mesh: MeshData, options?: CollisionOptions): CollisionSource;
|
|
43
|
+
/** A prop's hulls, and how much empty space they added. */
|
|
44
|
+
export interface PropHulls {
|
|
45
|
+
/** xyz-packed points per hull, as `COLL` writes them and `hullShape` takes them. */
|
|
46
|
+
readonly hulls: readonly Float32Array[];
|
|
47
|
+
/** `(hullVolume − sourceVolume) / sourceVolume`, from the decomposition itself. */
|
|
48
|
+
readonly bloat: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `mesh` decomposed into convex hulls the container can hold.
|
|
52
|
+
*
|
|
53
|
+
* **Asked for inside the caps rather than checked against them afterwards.** A decomposition is the
|
|
54
|
+
* expensive part of baking a prop, and one that comes back with thirty-three hulls is one that has
|
|
55
|
+
* to be thrown away and asked for again — so the cap is what it is asked for. A hull that still
|
|
56
|
+
* arrives with more points than a record can hold is refused by name, because silently dropping its
|
|
57
|
+
* points changes the shape a game collides against without telling anybody.
|
|
58
|
+
*/
|
|
59
|
+
export declare function propHulls(mesh: MeshData | CollisionSource, options?: DecomposeOptions): PropHulls;
|
package/dist/collide.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A captured mesh as something to stand on and to put in a file.
|
|
3
|
+
*
|
|
4
|
+
* **The mesh a capture draws and the mesh it collides against are the same triangles and not the
|
|
5
|
+
* same array.** What comes out of `marchVolume` and `decimate` is built for a picture: it carries
|
|
6
|
+
* normals and colours a collision test never reads, and it carries the occasional triangle with no
|
|
7
|
+
* area, which is harmless in a render and is not harmless in a contact — a plane needs a normal,
|
|
8
|
+
* and a triangle with no area has none. So the collision mesh is the drawn one with the arealess
|
|
9
|
+
* triangles taken out and the vertices nothing uses any more taken with them.
|
|
10
|
+
*
|
|
11
|
+
* **A room is a static mesh body and a prop is a set of hulls, and the difference is not size.** A
|
|
12
|
+
* mesh body is exact and cannot move: every triangle is tested as it stands, which is what a floor
|
|
13
|
+
* and a wall want. A convex decomposition is approximate and can be thrown: a hull has a centre of
|
|
14
|
+
* mass, an inertia and a cheap support function, which is what a crate wants. Giving a room hulls
|
|
15
|
+
* would round off its corners; giving a crate a mesh body would leave it unable to be picked up.
|
|
16
|
+
*
|
|
17
|
+
* **The container's caps are the decomposition's brief.** `COLL` holds at most thirty-two hulls of
|
|
18
|
+
* at most sixty-four points, so a decomposition that ignored them would produce a prop that cannot
|
|
19
|
+
* be written — found at the writer, after the expensive part. It is asked for inside them instead.
|
|
20
|
+
*/
|
|
21
|
+
import { MAX_COLLIDER_HULLS } from '@driftengine/drft';
|
|
22
|
+
import { decomposeConvex } from '@driftengine/physics';
|
|
23
|
+
const DEFAULT_MINIMUM_AREA = 1e-6;
|
|
24
|
+
/** `mesh`'s triangles, less the ones with no area, renumbered onto the vertices that remain. */
|
|
25
|
+
export function collisionMesh(mesh, options = {}) {
|
|
26
|
+
const minimumArea = options.minimumArea ?? DEFAULT_MINIMUM_AREA;
|
|
27
|
+
const triangles = mesh.indices.length / 3;
|
|
28
|
+
const renumbered = new Map();
|
|
29
|
+
const positions = [];
|
|
30
|
+
const indices = [];
|
|
31
|
+
let dropped = 0;
|
|
32
|
+
for (let face = 0; face < triangles; face += 1) {
|
|
33
|
+
const a = mesh.indices[face * 3];
|
|
34
|
+
const b = mesh.indices[face * 3 + 1];
|
|
35
|
+
const c = mesh.indices[face * 3 + 2];
|
|
36
|
+
if (areaOf(mesh.positions, a, b, c) < minimumArea) {
|
|
37
|
+
dropped += 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const vertex of [a, b, c]) {
|
|
41
|
+
let at = renumbered.get(vertex);
|
|
42
|
+
if (at === undefined) {
|
|
43
|
+
at = positions.length / 3;
|
|
44
|
+
renumbered.set(vertex, at);
|
|
45
|
+
for (let k = 0; k < 3; k += 1)
|
|
46
|
+
positions.push(mesh.positions[vertex * 3 + k]);
|
|
47
|
+
}
|
|
48
|
+
indices.push(at);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
positions: Float32Array.from(positions),
|
|
53
|
+
indices: Uint32Array.from(indices),
|
|
54
|
+
dropped,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Twice the area of a triangle, halved: the length of the cross product of two of its edges. */
|
|
58
|
+
function areaOf(positions, a, b, c) {
|
|
59
|
+
const ux = positions[b * 3] - positions[a * 3];
|
|
60
|
+
const uy = positions[b * 3 + 1] - positions[a * 3 + 1];
|
|
61
|
+
const uz = positions[b * 3 + 2] - positions[a * 3 + 2];
|
|
62
|
+
const vx = positions[c * 3] - positions[a * 3];
|
|
63
|
+
const vy = positions[c * 3 + 1] - positions[a * 3 + 1];
|
|
64
|
+
const vz = positions[c * 3 + 2] - positions[a * 3 + 2];
|
|
65
|
+
const nx = uy * vz - uz * vy;
|
|
66
|
+
const ny = uz * vx - ux * vz;
|
|
67
|
+
const nz = ux * vy - uy * vx;
|
|
68
|
+
return Math.sqrt(nx * nx + ny * ny + nz * nz) / 2;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* `mesh` decomposed into convex hulls the container can hold.
|
|
72
|
+
*
|
|
73
|
+
* **Asked for inside the caps rather than checked against them afterwards.** A decomposition is the
|
|
74
|
+
* expensive part of baking a prop, and one that comes back with thirty-three hulls is one that has
|
|
75
|
+
* to be thrown away and asked for again — so the cap is what it is asked for. A hull that still
|
|
76
|
+
* arrives with more points than a record can hold is refused by name, because silently dropping its
|
|
77
|
+
* points changes the shape a game collides against without telling anybody.
|
|
78
|
+
*/
|
|
79
|
+
export function propHulls(mesh, options = {}) {
|
|
80
|
+
const decomposition = decomposeConvex(mesh.positions, mesh.indices, {
|
|
81
|
+
...options,
|
|
82
|
+
maxHulls: Math.min(options.maxHulls ?? MAX_COLLIDER_HULLS, MAX_COLLIDER_HULLS),
|
|
83
|
+
});
|
|
84
|
+
/*
|
|
85
|
+
* **The points need no cap of their own**, and it is worth saying why rather than checking for
|
|
86
|
+
* something that cannot happen. A part carries at most one point per support direction, which is
|
|
87
|
+
* fifty, and a collider record holds sixty-four — so the decomposition is already inside the
|
|
88
|
+
* container by construction. `collide.test.ts` asserts that relationship rather than this file
|
|
89
|
+
* testing each hull against a limit it can never reach.
|
|
90
|
+
*/
|
|
91
|
+
return { hulls: decomposition.parts.map((part) => part.points), bloat: decomposition.bloat };
|
|
92
|
+
}
|