@kite3d/engine 0.15.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/dist/authoring.d.ts +54 -0
- package/dist/authoring.js +165 -0
- package/dist/authoring.js.map +1 -0
- package/dist/authoringValidation.d.ts +110 -0
- package/dist/authoringValidation.js +488 -0
- package/dist/authoringValidation.js.map +1 -0
- package/dist/defaults.d.ts +2 -0
- package/dist/fileTypes.d.ts +5 -0
- package/dist/fileTypes.js +51 -0
- package/dist/fileTypes.js.map +1 -0
- package/dist/importMap.d.ts +15 -0
- package/dist/importMap.js +62 -0
- package/dist/importMap.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2756 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations.js +5 -0
- package/dist/migrations.js.map +1 -0
- package/dist/paths.d.ts +9 -0
- package/dist/paths.js +13 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugins/GeneratorComponent.d.ts +40 -0
- package/dist/plugins/HtmlUiComponent.d.ts +52 -0
- package/dist/plugins/HtmlUiComponent.example.d.ts +0 -0
- package/dist/plugins/cannon/Cannon3DBodyComponent.d.ts +27 -0
- package/dist/plugins/cannon/Cannon3DShapeComponent.d.ts +57 -0
- package/dist/plugins/cannon/CannonPhysicsPlugin.d.ts +63 -0
- package/dist/plugins/cannon/CannonRagdollComponent.d.ts +148 -0
- package/dist/plugins/cannon/helper.d.ts +24 -0
- package/dist/plugins/cannon/threeToCannon.d.ts +63 -0
- package/dist/plugins/cannon/utils.d.ts +9 -0
- package/dist/projectFormat.js +108 -0
- package/dist/projectFormat.js.map +1 -0
- package/dist/runtime/createGame.d.ts +29 -0
- package/dist/runtime/index.d.ts +18 -0
- package/dist/runtime/migrations.d.ts +5 -0
- package/dist/runtime/nestedAssets.d.ts +26 -0
- package/dist/runtime/projectFormat.d.ts +83 -0
- package/dist/runtime/version.d.ts +1 -0
- package/dist/runtime.js +72835 -0
- package/dist/runtime.js.map +1 -0
- package/dist/sceneSerialization.d.ts +17 -0
- package/dist/sceneSerialization.js +174 -0
- package/dist/sceneSerialization.js.map +1 -0
- package/dist/scripts.d.ts +17 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/package.json +86 -0
- package/src/authoring.ts +293 -0
- package/src/authoringValidation.ts +815 -0
- package/src/defaults.ts +277 -0
- package/src/fileTypes.ts +53 -0
- package/src/importMap.ts +105 -0
- package/src/index.ts +15 -0
- package/src/paths.ts +9 -0
- package/src/plugins/GeneratorComponent.ts +275 -0
- package/src/plugins/HtmlUiComponent.example.ts +202 -0
- package/src/plugins/HtmlUiComponent.md +219 -0
- package/src/plugins/HtmlUiComponent.ts +320 -0
- package/src/plugins/cannon/Cannon3DBodyComponent.ts +227 -0
- package/src/plugins/cannon/Cannon3DShapeComponent.ts +258 -0
- package/src/plugins/cannon/CannonPhysicsPlugin.ts +409 -0
- package/src/plugins/cannon/CannonRagdollComponent.ts +1170 -0
- package/src/plugins/cannon/helper.ts +255 -0
- package/src/plugins/cannon/threeToCannon.ts +441 -0
- package/src/plugins/cannon/utils.ts +185 -0
- package/src/runtime/createGame.ts +337 -0
- package/src/runtime/index.ts +19 -0
- package/src/runtime/migrations.ts +6 -0
- package/src/runtime/nestedAssets.ts +226 -0
- package/src/runtime/projectFormat.ts +233 -0
- package/src/runtime/version.ts +3 -0
- package/src/sceneSerialization.ts +289 -0
- package/src/scripts.ts +52 -0
package/src/defaults.ts
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import type {ProjectConfigSettings} from './runtime/projectFormat.ts'
|
|
2
|
+
|
|
3
|
+
export const emptyProjectSettings = {
|
|
4
|
+
plugins: [
|
|
5
|
+
{
|
|
6
|
+
"import": "threepipe",
|
|
7
|
+
"className": "SSAAPlugin"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"import": "threepipe",
|
|
11
|
+
"className": "AssetExporterPlugin"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"import": "threepipe",
|
|
15
|
+
"className": "TransformAnimationPlugin"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"import": "threepipe",
|
|
19
|
+
"className": "DepthBufferPlugin"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"import": "threepipe",
|
|
23
|
+
"className": "NormalBufferPlugin"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"import": "threepipe",
|
|
27
|
+
"className": "FullScreenPlugin"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"import": "threepipe",
|
|
31
|
+
"className": "ObjectConstraintsPlugin"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"import": "threepipe",
|
|
35
|
+
"className": "TransformControlsPlugin"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"import": "threepipe",
|
|
39
|
+
"className": "AssetExporterPlugin"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"import": "threepipe",
|
|
43
|
+
"className": "ClearcoatTintPlugin"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"import": "threepipe",
|
|
47
|
+
"className": "FragmentClippingExtensionPlugin"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"import": "threepipe",
|
|
51
|
+
"className": "NoiseBumpMaterialPlugin"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"import": "threepipe",
|
|
55
|
+
"className": "CustomBumpMapPlugin"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"import": "threepipe",
|
|
59
|
+
"className": "ParallaxMappingPlugin",
|
|
60
|
+
"params": [
|
|
61
|
+
false
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"import": "threepipe",
|
|
66
|
+
"className": "GLTFKHRMaterialVariantsPlugin"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"import": "threepipe",
|
|
70
|
+
"className": "VirtualCamerasPlugin"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"import": "threepipe",
|
|
74
|
+
"className": "RenderTargetPreviewPlugin",
|
|
75
|
+
"params": [
|
|
76
|
+
false
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"import": "threepipe",
|
|
81
|
+
"className": "HDRiGroundPlugin",
|
|
82
|
+
"params": [
|
|
83
|
+
false,
|
|
84
|
+
true
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"import": "threepipe",
|
|
89
|
+
"className": "VignettePlugin",
|
|
90
|
+
"params": [
|
|
91
|
+
false
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"import": "threepipe",
|
|
96
|
+
"className": "ChromaticAberrationPlugin",
|
|
97
|
+
"params": [
|
|
98
|
+
false
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"import": "threepipe",
|
|
103
|
+
"className": "FilmicGrainPlugin",
|
|
104
|
+
"params": [
|
|
105
|
+
false
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"import": "threepipe",
|
|
110
|
+
"className": "SSAOPlugin",
|
|
111
|
+
"params": [
|
|
112
|
+
1009,
|
|
113
|
+
1
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"import": "threepipe",
|
|
118
|
+
"className": "ContactShadowGroundPlugin"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"import": "threepipe",
|
|
122
|
+
"className": "DeviceOrientationControlsPlugin"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"import": "threepipe",
|
|
126
|
+
"className": "PointerLockControlsPlugin"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"import": "threepipe",
|
|
130
|
+
"className": "ThreeFirstPersonControlsPlugin"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"import": "threepipe",
|
|
134
|
+
"className": "MeshOptSimplifyModifierPlugin",
|
|
135
|
+
"params": [
|
|
136
|
+
false
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"import": "@threepipe/webgi-plugins",
|
|
141
|
+
"className": "AnisotropyPlugin",
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"import": "@threepipe/webgi-plugins",
|
|
145
|
+
"className": "BloomPlugin",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"import": "@threepipe/webgi-plugins",
|
|
149
|
+
"className": "SSReflectionPlugin",
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"import": "@threepipe/webgi-plugins",
|
|
153
|
+
"className": "TemporalAAPlugin",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"import": "@threepipe/webgi-plugins",
|
|
157
|
+
"className": "VelocityBufferPlugin",
|
|
158
|
+
params: [1009, false],
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"import": "@threepipe/webgi-plugins",
|
|
162
|
+
"className": "DepthOfFieldPlugin",
|
|
163
|
+
params: [false],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"import": "@threepipe/webgi-plugins",
|
|
167
|
+
"className": "SSContactShadowsPlugin",
|
|
168
|
+
params: [false],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"import": "@threepipe/webgi-plugins",
|
|
172
|
+
"className": "OutlinePlugin",
|
|
173
|
+
params: [false],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"import": "@threepipe/webgi-plugins",
|
|
177
|
+
"className": "SSGIPlugin",
|
|
178
|
+
params: [undefined, 1, false],
|
|
179
|
+
},
|
|
180
|
+
// GLTFDracoExportPlugin, GLTFSpecGlossinessConverterPlugin
|
|
181
|
+
{
|
|
182
|
+
"import": "@threepipe/plugin-gltf-transform",
|
|
183
|
+
"className": "GLTFDracoExportPlugin",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"import": "@threepipe/plugin-gltf-transform",
|
|
187
|
+
"className": "GLTFSpecGlossinessConverterPlugin",
|
|
188
|
+
},
|
|
189
|
+
// MaterialConfiguratorPlugin, SwitchNodePlugin
|
|
190
|
+
{
|
|
191
|
+
"import": "@threepipe/plugin-configurator",
|
|
192
|
+
"className": "MaterialConfiguratorPlugin",
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"import": "@threepipe/plugin-configurator",
|
|
196
|
+
"className": "SwitchNodePlugin",
|
|
197
|
+
},
|
|
198
|
+
...['B3DMLoadPlugin', 'CMPTLoadPlugin', 'DeepZoomImageLoadPlugin', 'EnvironmentControlsPlugin', 'GlobeControlsPlugin', 'I3DMLoadPlugin', 'PNTSLoadPlugin', 'TilesRendererPlugin'].map(className => ({
|
|
199
|
+
import: '@threepipe/plugin-3d-tiles-renderer',
|
|
200
|
+
className,
|
|
201
|
+
})),
|
|
202
|
+
{
|
|
203
|
+
import: '@threepipe/plugin-assimpjs',
|
|
204
|
+
className: 'AssimpJsPlugin',
|
|
205
|
+
params: [false],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
import: '@threepipe/plugin-path-tracing',
|
|
209
|
+
className: 'ThreeGpuPathTracerPlugin',
|
|
210
|
+
params: [false],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
import: '@threepipe/plugin-blend-importer',
|
|
214
|
+
className: 'BlendLoadPlugin',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
import: '@threepipe/plugin-network',
|
|
218
|
+
className: 'TransfrSharePlugin',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
import: '@threepipe/plugin-troika-text',
|
|
222
|
+
className: 'TroikaTextPlugin',
|
|
223
|
+
},
|
|
224
|
+
...[
|
|
225
|
+
'TDSLoadPlugin',
|
|
226
|
+
'ThreeMFLoadPlugin',
|
|
227
|
+
'ColladaLoadPlugin',
|
|
228
|
+
'AMFLoadPlugin',
|
|
229
|
+
'GCodeLoadPlugin',
|
|
230
|
+
'BVHLoadPlugin',
|
|
231
|
+
'VOXLoadPlugin',
|
|
232
|
+
'MDDLoadPlugin',
|
|
233
|
+
'PCDLoadPlugin',
|
|
234
|
+
'TiltLoadPlugin',
|
|
235
|
+
'VRMLLoadPlugin',
|
|
236
|
+
'LDrawLoadPlugin',
|
|
237
|
+
'VTKLoadPlugin',
|
|
238
|
+
'XYZLoadPlugin',
|
|
239
|
+
].map(className => ({
|
|
240
|
+
import: '@threepipe/plugins-extra-importers',
|
|
241
|
+
className,
|
|
242
|
+
})),
|
|
243
|
+
],
|
|
244
|
+
dependencies: [{
|
|
245
|
+
key: '@threepipe/webgi-plugins',
|
|
246
|
+
version: '0.6.1',
|
|
247
|
+
}, {
|
|
248
|
+
key: '@threepipe/plugin-gltf-transform',
|
|
249
|
+
version: 'latest',
|
|
250
|
+
}, {
|
|
251
|
+
key: '@threepipe/plugin-configurator',
|
|
252
|
+
version: 'latest',
|
|
253
|
+
}, {
|
|
254
|
+
key: '@threepipe/plugin-3d-tiles-renderer',
|
|
255
|
+
version: 'latest',
|
|
256
|
+
}, {
|
|
257
|
+
key: '@threepipe/plugin-assimpjs',
|
|
258
|
+
version: 'latest',
|
|
259
|
+
}, {
|
|
260
|
+
key: '@threepipe/plugin-path-tracing',
|
|
261
|
+
version: 'latest',
|
|
262
|
+
}, {
|
|
263
|
+
key: '@threepipe/plugin-blend-importer',
|
|
264
|
+
version: 'latest',
|
|
265
|
+
}, {
|
|
266
|
+
key: '@threepipe/plugin-network',
|
|
267
|
+
version: 'latest',
|
|
268
|
+
}, {
|
|
269
|
+
key: '@threepipe/plugin-troika-text',
|
|
270
|
+
version: 'latest',
|
|
271
|
+
}, {
|
|
272
|
+
key: '@threepipe/plugins-extra-importers',
|
|
273
|
+
version: 'latest',
|
|
274
|
+
}],
|
|
275
|
+
scripts: [],
|
|
276
|
+
viewer: {},
|
|
277
|
+
} as ProjectConfigSettings
|
package/src/fileTypes.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type Kite3dFileType = 'plugin' | 'script' | 'material' | 'image'
|
|
2
|
+
|
|
3
|
+
export const typesExts: Partial<Record<Kite3dFileType, string[]>> = {
|
|
4
|
+
'plugin': ['.plugin.js', '.plugin.ts'],
|
|
5
|
+
'script': ['.script.js', '.script.ts'],
|
|
6
|
+
'material': ['.mat', '.mat.json'],
|
|
7
|
+
'image': ['.png', '.jpeg', '.jpg', '.gif', '.bmp', '.tiff', '.webp', '.hdr', '.exr', '.ktx2', '.svg'],
|
|
8
|
+
// 'texture': ['.png', '.jpeg', '.jpg', '.gif', '.bmp', '.tiff', '.webp', '.tex.json'],
|
|
9
|
+
// 'geometry': ['.glb', '.gltf', '.obj', '.fbx', '.ply', '.stl', '.geom.json'],
|
|
10
|
+
// 'object': ['.glb', '.gltf', '.obj', '.fbx', '.ply', '.stl', '.geom.json'],
|
|
11
|
+
}
|
|
12
|
+
export const mimeToExt: Record<string, string> = {
|
|
13
|
+
'image/jpeg': 'jpg',
|
|
14
|
+
'image/png': 'png',
|
|
15
|
+
'image/svg+xml': 'svg',
|
|
16
|
+
'image/webp': 'webp',
|
|
17
|
+
'image/x-exr': 'exr',
|
|
18
|
+
'image/x-hdr': 'hdr',
|
|
19
|
+
'model/gltf+binary': 'glb',
|
|
20
|
+
'model/gltf+json': 'gltf',
|
|
21
|
+
'model/gltf': 'gltf',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const extensionMimeTypes: Record<string, string> = {
|
|
25
|
+
'.html': 'text/html; charset=utf-8',
|
|
26
|
+
'.css': 'text/css; charset=utf-8',
|
|
27
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
28
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
29
|
+
'.ts': 'text/typescript; charset=utf-8',
|
|
30
|
+
'.json': 'application/json; charset=utf-8',
|
|
31
|
+
'.gltf': 'model/gltf+json',
|
|
32
|
+
'.glb': 'model/gltf-binary',
|
|
33
|
+
'.png': 'image/png',
|
|
34
|
+
'.jpg': 'image/jpeg',
|
|
35
|
+
'.jpeg': 'image/jpeg',
|
|
36
|
+
'.gif': 'image/gif',
|
|
37
|
+
'.webp': 'image/webp',
|
|
38
|
+
'.svg': 'image/svg+xml',
|
|
39
|
+
'.wasm': 'application/wasm',
|
|
40
|
+
'.mp3': 'audio/mpeg',
|
|
41
|
+
'.ogg': 'audio/ogg',
|
|
42
|
+
'.wav': 'audio/wav',
|
|
43
|
+
'.mp4': 'video/mp4',
|
|
44
|
+
'.webm': 'video/webm',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function mimeTypeForPath(path: string): string {
|
|
48
|
+
const lower = path.toLowerCase()
|
|
49
|
+
const extension = Object.keys(extensionMimeTypes)
|
|
50
|
+
.sort((a, b) => b.length - a.length)
|
|
51
|
+
.find((candidate) => lower.endsWith(candidate))
|
|
52
|
+
return extension ? extensionMimeTypes[extension] : 'application/octet-stream'
|
|
53
|
+
}
|
package/src/importMap.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type {ProjectDependency} from './runtime/projectFormat.ts'
|
|
2
|
+
|
|
3
|
+
export const RUNTIME_SPECIFIERS = [
|
|
4
|
+
'threepipe',
|
|
5
|
+
'three',
|
|
6
|
+
'uiconfig.js',
|
|
7
|
+
'ts-browser-helpers',
|
|
8
|
+
'@kite3d/engine',
|
|
9
|
+
] as const
|
|
10
|
+
|
|
11
|
+
export interface InstalledPluginImport {
|
|
12
|
+
specifier: string
|
|
13
|
+
entry: string
|
|
14
|
+
rootUrl: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Create one safe import map for both editor play mode and published games. */
|
|
18
|
+
export function dependencyImportMap(
|
|
19
|
+
dependencies: ProjectDependency[],
|
|
20
|
+
runtimeUrl = './_blitz/runtime.js',
|
|
21
|
+
installedPlugins: InstalledPluginImport[] = [],
|
|
22
|
+
): {imports: Record<string, string>} {
|
|
23
|
+
const extras = uniqueDependencies(dependencies).filter(isMappableDependency)
|
|
24
|
+
const pluginSpecifiers = installedPlugins
|
|
25
|
+
.map(({specifier}) => specifier)
|
|
26
|
+
.filter((specifier) => !RUNTIME_SPECIFIERS.includes(specifier as typeof RUNTIME_SPECIFIERS[number]))
|
|
27
|
+
const externals = [...new Set([...RUNTIME_SPECIFIERS, ...extras.map(({key}) => key), ...pluginSpecifiers])]
|
|
28
|
+
const imports: Record<string, string> = Object.fromEntries(
|
|
29
|
+
RUNTIME_SPECIFIERS.map((specifier) => [specifier, runtimeUrl]),
|
|
30
|
+
)
|
|
31
|
+
for (const dependency of extras) {
|
|
32
|
+
const baseUrl = dependency.url || `https://esm.sh/${dependency.key}@${dependency.version}`
|
|
33
|
+
const separator = baseUrl.includes('?') ? '&' : '?'
|
|
34
|
+
imports[dependency.key] = `${baseUrl}${separator}external=${externals.join(',')}`
|
|
35
|
+
}
|
|
36
|
+
// Installed plugins map their bare name to the package entry and their trailing-slash name to the package root.
|
|
37
|
+
for (const plugin of installedPlugins) {
|
|
38
|
+
if (RUNTIME_SPECIFIERS.includes(plugin.specifier as typeof RUNTIME_SPECIFIERS[number])) continue
|
|
39
|
+
const rootUrl = plugin.rootUrl.endsWith('/') ? plugin.rootUrl : `${plugin.rootUrl}/`
|
|
40
|
+
imports[plugin.specifier] = `${rootUrl}${plugin.entry.replace(/^\.\//, '')}`
|
|
41
|
+
imports[`${plugin.specifier}/`] = rootUrl
|
|
42
|
+
}
|
|
43
|
+
return {imports}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Read dependency declarations without exposing package-manager-only specs. */
|
|
47
|
+
export function projectDependencies(packageJson: Record<string, unknown>): ProjectDependency[] {
|
|
48
|
+
const result: ProjectDependency[] = []
|
|
49
|
+
const dependencies = packageJson.dependencies
|
|
50
|
+
if (isRecord(dependencies)) {
|
|
51
|
+
for (const [key, version] of Object.entries(dependencies)) {
|
|
52
|
+
if (typeof version === 'string') result.push({key, version})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const kite3d = packageJson.kite3d
|
|
56
|
+
const imports = isRecord(kite3d) ? kite3d.imports : undefined
|
|
57
|
+
if (isRecord(imports)) {
|
|
58
|
+
for (const [key, value] of Object.entries(imports)) {
|
|
59
|
+
if (typeof value !== 'string') continue
|
|
60
|
+
result.push(value.startsWith('@')
|
|
61
|
+
? {key, version: value.slice(1)}
|
|
62
|
+
: {key, version: '', url: value})
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Return configured plugin names that are exact project dependency keys. */
|
|
69
|
+
export function projectPluginNames(packageJson: Record<string, unknown>): string[] {
|
|
70
|
+
const dependencies = isRecord(packageJson.dependencies) ? packageJson.dependencies : {}
|
|
71
|
+
const kite3d = isRecord(packageJson.kite3d) ? packageJson.kite3d : {}
|
|
72
|
+
const plugins = Array.isArray(kite3d.plugins) ? kite3d.plugins : []
|
|
73
|
+
const names = plugins.flatMap((plugin) => {
|
|
74
|
+
const specifier = typeof plugin === 'string'
|
|
75
|
+
? plugin.replace(/\(.*\)$/, '').trim()
|
|
76
|
+
: isRecord(plugin) && typeof plugin.import === 'string' ? plugin.import : ''
|
|
77
|
+
const matches = Object.keys(dependencies)
|
|
78
|
+
.filter((name) => specifier === name || specifier.startsWith(`${name}:`))
|
|
79
|
+
.sort((left, right) => right.length - left.length)
|
|
80
|
+
return matches.length ? [matches[0]] : []
|
|
81
|
+
})
|
|
82
|
+
return [...new Set(names)]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function uniqueDependencies(dependencies: ProjectDependency[]): ProjectDependency[] {
|
|
86
|
+
const byKey = new Map<string, ProjectDependency>()
|
|
87
|
+
for (const dependency of dependencies) {
|
|
88
|
+
if (!byKey.has(dependency.key)) byKey.set(dependency.key, dependency)
|
|
89
|
+
}
|
|
90
|
+
return [...byKey.values()]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isMappableDependency(dependency: ProjectDependency): boolean {
|
|
94
|
+
if (RUNTIME_SPECIFIERS.includes(dependency.key as typeof RUNTIME_SPECIFIERS[number])) return false
|
|
95
|
+
if (dependency.key.startsWith('@kite3d/')) return false
|
|
96
|
+
return Boolean(dependency.url) || isSemverSpec(dependency.version)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function isSemverSpec(value: string): boolean {
|
|
100
|
+
return /^(?:[~^]|[<>]=?)?v?\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(value.trim())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
104
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
105
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './runtime/index.ts'
|
|
2
|
+
export * from './scripts.ts'
|
|
3
|
+
export * from './importMap.ts'
|
|
4
|
+
export * from './defaults.ts'
|
|
5
|
+
export * from './fileTypes.ts'
|
|
6
|
+
export * from './paths.ts'
|
|
7
|
+
export * from './sceneSerialization.ts'
|
|
8
|
+
export * from './authoring.ts'
|
|
9
|
+
export * from './authoringValidation.ts'
|
|
10
|
+
export * from './plugins/HtmlUiComponent.ts'
|
|
11
|
+
export * from './plugins/GeneratorComponent.ts'
|
|
12
|
+
export * from './plugins/cannon/CannonPhysicsPlugin.ts'
|
|
13
|
+
export * from './plugins/cannon/Cannon3DBodyComponent.ts'
|
|
14
|
+
export * from './plugins/cannon/Cannon3DShapeComponent.ts'
|
|
15
|
+
export * from './plugins/cannon/CannonRagdollComponent.ts'
|
package/src/paths.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const KITE3D_DIRECTORY = '.kite3d'
|
|
2
|
+
export const DEPLOYS_PATH = `${KITE3D_DIRECTORY}/deploys.json`
|
|
3
|
+
export const JOURNAL_PATH = `${KITE3D_DIRECTORY}/journal.jsonl`
|
|
4
|
+
export const STATE_PATH = `${KITE3D_DIRECTORY}/state.json`
|
|
5
|
+
export const CONSOLE_PATH = `${KITE3D_DIRECTORY}/console.log`
|
|
6
|
+
export const THUMBS_DIRECTORY = `${KITE3D_DIRECTORY}/thumbs`
|
|
7
|
+
export const BACKUPS_DIRECTORY = `${KITE3D_DIRECTORY}/backups`
|
|
8
|
+
export const RUNNING_DIRECTORY = `${KITE3D_DIRECTORY}/running`
|
|
9
|
+
export const KITE3D_SERVER_CLIENT_ID = 'kite3d-server'
|