@threlte/gltf 1.0.0-next.9 → 1.0.1
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/CHANGELOG.md +55 -0
- package/{readme.md → README.md} +62 -11
- package/package.json +4 -3
- package/src/index.js +3 -7
- package/src/utils/parser.js +24 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @threlte/gltf
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ee1d319: Update package READMEs to fix banners.
|
|
8
|
+
|
|
9
|
+
## 1.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- a07850e4: Removed the name from the exported preload function (seems silly and might collide anyway), updated deps and included three-stdlib instead of rolling an own implementation of GLTFLoader and DRACOLoader. Added option to make the component suspense-ready, updated README.
|
|
14
|
+
- 3a5376e2: Adapted gltf package to Threlte 6 T syntax
|
|
15
|
+
- d5abde5: Simplified root option to more reasonable approach. When no root is given, the path supplied will be normalized and used as a file path, if root is given, takes full control.
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- e91cc09: await instead of if clause for less if-blocks (helps with transitions)
|
|
20
|
+
- 72c71414: Added option to add a preload method that makes preloading an asset easy. Also, added the option to make an isolated component (so no \$\$restProps usage)
|
|
21
|
+
- 05d9170: Added forwarding event handlers
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 6d56d11: Added proper types for new slots error & fallback
|
|
26
|
+
- 119a04d: Downgrading three and reusing own GLTFLoader and DRACOLoader implementations
|
|
27
|
+
- 89e0c7a: Updated dependencies
|
|
28
|
+
- 16e75c31: Fixed a bug where the suspense was created in the wrong place when preloading was activated.
|
|
29
|
+
- da70d570: typo
|
|
30
|
+
- 81834dd4: Refactored the pascal case function
|
|
31
|
+
- 124eabab: Fixed preload method to return a Promise
|
|
32
|
+
- 89710f3: Removed logs
|
|
33
|
+
|
|
34
|
+
## 1.0.0-next.13
|
|
35
|
+
|
|
36
|
+
### Major Changes
|
|
37
|
+
|
|
38
|
+
- d5abde5: Simplified root option to more reasonable approach. When no root is given, the path supplied will be normalized and used as a file path, if root is given, takes full control.
|
|
39
|
+
|
|
40
|
+
## 1.0.0-next.12
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- 6d56d11c: Added proper types for new slots error & fallback
|
|
45
|
+
|
|
46
|
+
## 1.0.0-next.11
|
|
47
|
+
|
|
48
|
+
### Minor Changes
|
|
49
|
+
|
|
50
|
+
- e91cc094: await instead of if clause for less if-blocks (helps with transitions)
|
|
51
|
+
|
|
52
|
+
## 1.0.0-next.10
|
|
53
|
+
|
|
54
|
+
### Minor Changes
|
|
55
|
+
|
|
56
|
+
- 05d91701: Added forwarding event handlers
|
|
57
|
+
|
|
3
58
|
## 1.0.0-next.9
|
|
4
59
|
|
|
5
60
|
### Patch Changes
|
package/{readme.md → README.md}
RENAMED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="right">
|
|
2
|
+
<a href="https://www.npmjs.com/package/@threlte/gltf">
|
|
3
|
+
<img alt="npm" src="https://img.shields.io/npm/v/@threlte/gltf?color=fe4100&labelColor=171d27&logo=npm&logoColor=white"/>
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://github.com/threlte/threlte/blob/main/LICENSE.md">
|
|
6
|
+
<img alt="license" src="https://img.shields.io/npm/l/@threlte/core?color=fe4100&labelColor=171d27&logo=git&logoColor=white"/>
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://discord.com/channels/985983540804091964">
|
|
9
|
+
<img alt="discord" src="https://img.shields.io/discord/985983540804091964?label=discord&color=fe4100&labelColor=171d27&logo=discord&logoColor=white"/>
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://threlte.xyz">
|
|
12
|
+
<img alt="docs" src="https://img.shields.io/website?down_color=red&down_message=offline&label=docs&color=fe4100&labelColor=171d27&up_message=online&url=https%3A%2F%2Fthrelte.xyz&logo=svelte&logoColor=white"/>
|
|
13
|
+
</a>
|
|
14
|
+
</div>
|
|
2
15
|
|
|
3
|
-
|
|
16
|
+
<a href="https://threlte.xyz">
|
|
17
|
+
<img src="https://threlte.xyz/logo/threlte-banner.jpg"/>
|
|
18
|
+
</a>
|
|
19
|
+
|
|
20
|
+
## Rapidly Build Interactive 3D Apps for the Web
|
|
21
|
+
|
|
22
|
+
Threlte is a [Svelte](https://svelte.dev/) library that simplifies creating 3D apps for the web. It provides a **declarative**, **type-safe**, **reactive** and **interactive** API out-of-the-box.
|
|
23
|
+
|
|
24
|
+
Threlte's **3D rendering** is powered by [Three.js](https://threejs.org/), and it also provides a **physics engine** through [Rapier](https://rapier.rs/) and an **animation studio** via [Theatre.js](https://www.theatrejs.com/); see [packages](#packages) for details.
|
|
25
|
+
|
|
26
|
+
Check out our **[documentation](https://threlte.xyz)** and our **[Discord community](https://discord.gg/EqUBCfCaGm)**.
|
|
27
|
+
|
|
28
|
+
## @threlte/gltf
|
|
29
|
+
|
|
30
|
+
[@threlte/gltf](https://threlte.xyz/docs/reference/gltf/getting-started) gives you a CLI to that turn GLTF assets into declarative and reusable Threlte components.
|
|
31
|
+
|
|
32
|
+
This helps with performance optimization for asset-heavy Threlte apps. It also allows you to modify your GLTF assets as Svelte components, instead of working with 3D software like Blender.
|
|
33
|
+
|
|
34
|
+
### Motivation
|
|
35
|
+
|
|
36
|
+
#### The GLTF workflow on the web is not ideal ...
|
|
4
37
|
|
|
5
38
|
- GLTF is thrown wholesale into the scene which prevents re-use, in threejs objects can only be mounted once
|
|
6
39
|
- Contents can only be found by traversal which is cumbersome and slow
|
|
@@ -9,7 +42,7 @@ A small command-line tool that turns GLTF assets into declarative and re-usable
|
|
|
9
42
|
- Model compression is complex and not easily achieved
|
|
10
43
|
- Models often have unnecessary nodes that cause extra work and matrix updates
|
|
11
44
|
|
|
12
|
-
|
|
45
|
+
#### @threlte/gltf fixes that
|
|
13
46
|
|
|
14
47
|
- 🧑💻 It creates a virtual graph of all objects and materials. Now you can easily alter contents and re-use.
|
|
15
48
|
- 🏎️ The graph gets pruned (empty groups, unnecessary transforms, ...) and will perform better.
|
|
@@ -44,6 +77,18 @@ Options
|
|
|
44
77
|
--debug, -D Debug output
|
|
45
78
|
```
|
|
46
79
|
|
|
80
|
+
### Requirements
|
|
81
|
+
|
|
82
|
+
- NodeJS must be installed
|
|
83
|
+
- The GLTF file has to be present in your projects `/public` folder
|
|
84
|
+
- [three](https://github.com/mrdoob/three.js/) (>= 122.x)
|
|
85
|
+
- @threlte/core > 5.0.0
|
|
86
|
+
- @threlte/core > 4.9.3
|
|
87
|
+
|
|
88
|
+
### Support
|
|
89
|
+
|
|
90
|
+
Have questions? Feel free to ask in our [Discord support forum](https://discord.com/channels/985983540804091964/1031843197963477002).
|
|
91
|
+
|
|
47
92
|
### A typical use-case
|
|
48
93
|
|
|
49
94
|
First you run your model through `@threlte/gltf`. `npx` allows you to use npm packages without installing them.
|
|
@@ -240,14 +285,20 @@ gltfLoader.load(url, (gltf) => {
|
|
|
240
285
|
})
|
|
241
286
|
```
|
|
242
287
|
|
|
243
|
-
## Requirements
|
|
244
288
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
-
|
|
289
|
+
## Contributing
|
|
290
|
+
|
|
291
|
+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
|
292
|
+
|
|
293
|
+
- **Filing Issues** - if you have feature requestions or you think you spotted a bug, [submit an issue](https://github.com/threlte/threlte/issues/new).
|
|
294
|
+
- **Contributing Code** - if you would like to drop us a PR, read the [contribution guide](https://github.com/threlte/threlte/blob/main/CONTRIBUTING.md) first.
|
|
295
|
+
|
|
296
|
+
## Sponsors
|
|
297
|
+
|
|
298
|
+
[](https://vercel.com/?utm_source=threlte&utm_campaign=oss)
|
|
299
|
+
|
|
300
|
+
---
|
|
250
301
|
|
|
251
|
-
|
|
302
|
+
### License
|
|
252
303
|
|
|
253
|
-
|
|
304
|
+
The MIT License (MIT). Please see the [License File](LICENSE.md) for more information.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/gltf",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "GLTF to Threlte converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"fs-extra": "^9.0.1",
|
|
53
53
|
"husky": "^4.3.0",
|
|
54
54
|
"lint-staged": "^10.4.0",
|
|
55
|
-
"read-pkg-up": "^9.1.0"
|
|
55
|
+
"read-pkg-up": "^9.1.0",
|
|
56
|
+
"rimraf": "^5.0.1"
|
|
56
57
|
},
|
|
57
58
|
"husky": {
|
|
58
59
|
"hooks": {
|
|
@@ -65,6 +66,6 @@
|
|
|
65
66
|
]
|
|
66
67
|
},
|
|
67
68
|
"scripts": {
|
|
68
|
-
"cleanup": "
|
|
69
|
+
"cleanup": "rimraf node_modules"
|
|
69
70
|
}
|
|
70
71
|
}
|
package/src/index.js
CHANGED
|
@@ -25,12 +25,8 @@ function toArrayBuffer(buf) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export default function (file, output, options) {
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
const rootPath = options.root ? path.resolve(options.root) : path.dirname(file)
|
|
31
|
-
const relativePath = path.relative(rootPath, filePath) || ''
|
|
32
|
-
if (process.platform === 'win32') return relativePath.replace(/\\/g, '/')
|
|
33
|
-
return relativePath
|
|
28
|
+
function getFilePath(file) {
|
|
29
|
+
return `${options.root ?? '/'}${options.root ? path.basename(file) : path.normalize(file)}`
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
return new Promise((resolve, reject) => {
|
|
@@ -48,7 +44,7 @@ export default function (file, output, options) {
|
|
|
48
44
|
}
|
|
49
45
|
resolve()
|
|
50
46
|
|
|
51
|
-
const filePath =
|
|
47
|
+
const filePath = getFilePath(file)
|
|
52
48
|
const data = fs.readFileSync(file)
|
|
53
49
|
const arrayBuffer = toArrayBuffer(data)
|
|
54
50
|
|
package/src/utils/parser.js
CHANGED
|
@@ -2,7 +2,7 @@ import THREE from 'three'
|
|
|
2
2
|
import isVarName from './isVarName.js'
|
|
3
3
|
|
|
4
4
|
function parse(fileName, gltf, options = {}) {
|
|
5
|
-
const url =
|
|
5
|
+
const url = fileName
|
|
6
6
|
const animations = gltf.animations
|
|
7
7
|
const hasAnimations = animations.length > 0
|
|
8
8
|
|
|
@@ -149,24 +149,24 @@ function parse(fileName, gltf, options = {}) {
|
|
|
149
149
|
|
|
150
150
|
// Write out geometry first
|
|
151
151
|
if (obj.geometry) {
|
|
152
|
-
result += `geometry={
|
|
152
|
+
result += `geometry={gltf.${node}.geometry} `
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// Write out materials
|
|
156
156
|
if (obj.material) {
|
|
157
157
|
if (obj.material.name)
|
|
158
|
-
result += `material={
|
|
159
|
-
else result += `material={
|
|
158
|
+
result += `material={gltf.materials${sanitizeName(obj.material.name)}} `
|
|
159
|
+
else result += `material={gltf.${node}.material} `
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
if (obj.skeleton) result += `skeleton={
|
|
162
|
+
if (obj.skeleton) result += `skeleton={gltf.${node}.skeleton} `
|
|
163
163
|
if (obj.visible === false) result += `visible={false} `
|
|
164
164
|
if (obj.castShadow === true) result += `castShadow `
|
|
165
165
|
if (obj.receiveShadow === true) result += `receiveShadow `
|
|
166
166
|
if (obj.morphTargetDictionary)
|
|
167
|
-
result += `morphTargetDictionary={
|
|
167
|
+
result += `morphTargetDictionary={gltf.${node}.morphTargetDictionary} `
|
|
168
168
|
if (obj.morphTargetInfluences)
|
|
169
|
-
result += `morphTargetInfluences={
|
|
169
|
+
result += `morphTargetInfluences={gltf.${node}.morphTargetInfluences} `
|
|
170
170
|
if (obj.intensity && rNbr(obj.intensity)) result += `intensity={${rNbr(obj.intensity)}} `
|
|
171
171
|
//if (obj.power && obj.power !== 4 * Math.PI) result += `power={${rNbr(obj.power)}} `
|
|
172
172
|
if (obj.angle && obj.angle !== Math.PI / 3) result += `angle={${rDeg(obj.angle)}} `
|
|
@@ -378,7 +378,7 @@ function parse(fileName, gltf, options = {}) {
|
|
|
378
378
|
|
|
379
379
|
// Bail out on lights and bones
|
|
380
380
|
if (type === 'bone') {
|
|
381
|
-
return `<T is={
|
|
381
|
+
return `<T is={gltf.${node}} />\n`
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
// Collect children
|
|
@@ -476,7 +476,8 @@ function parse(fileName, gltf, options = {}) {
|
|
|
476
476
|
import { Group } from 'three'
|
|
477
477
|
import { ${[
|
|
478
478
|
'T',
|
|
479
|
-
options.types && !options.isolated ? 'type Props, type Events, type Slots' : ''
|
|
479
|
+
options.types && !options.isolated ? 'type Props, type Events, type Slots' : '',
|
|
480
|
+
!options.isolated && 'forwardEventHandlers'
|
|
480
481
|
]
|
|
481
482
|
.filter(Boolean)
|
|
482
483
|
.join(', ')} } from '@threlte/core'
|
|
@@ -534,7 +535,11 @@ ${
|
|
|
534
535
|
|
|
535
536
|
${options.types && !options.isolated ? 'type $$Props = Props<THREE.Group>' : ''}
|
|
536
537
|
${options.types && !options.isolated ? 'type $$Events = Events<THREE.Group>' : ''}
|
|
537
|
-
${
|
|
538
|
+
${
|
|
539
|
+
options.types && !options.isolated
|
|
540
|
+
? 'type $$Slots = Slots<THREE.Group> & { fallback: {}; error: { error: any } }'
|
|
541
|
+
: ''
|
|
542
|
+
}
|
|
538
543
|
|
|
539
544
|
export const ref = new Group()
|
|
540
545
|
|
|
@@ -551,12 +556,17 @@ ${
|
|
|
551
556
|
: ''
|
|
552
557
|
}
|
|
553
558
|
|
|
559
|
+
${!options.isolated ? 'const component = forwardEventHandlers()' : ''}
|
|
554
560
|
</script>
|
|
555
561
|
|
|
556
|
-
<T is={ref} dispose={false} ${!options.isolated ? '{...$$restProps}' : ''}>
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
{
|
|
562
|
+
<T is={ref} dispose={false} ${!options.isolated ? '{...$$restProps} bind:this={$component}' : ''}>
|
|
563
|
+
{#await gltf}
|
|
564
|
+
<slot name="fallback" />
|
|
565
|
+
{:then gltf}
|
|
566
|
+
${scene}
|
|
567
|
+
{:catch error}
|
|
568
|
+
<slot name="error" {error} />
|
|
569
|
+
{/await}
|
|
560
570
|
|
|
561
571
|
<slot {ref} />
|
|
562
572
|
</T>
|