@threlte/gltf 1.0.0-next.8 → 1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # @threlte/gltf
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 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.
8
+ - 3a5376e2: Adapted gltf package to Threlte 6 T syntax
9
+ - 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.
10
+
11
+ ### Minor Changes
12
+
13
+ - e91cc09: await instead of if clause for less if-blocks (helps with transitions)
14
+ - 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)
15
+ - 05d9170: Added forwarding event handlers
16
+
17
+ ### Patch Changes
18
+
19
+ - 6d56d11: Added proper types for new slots error & fallback
20
+ - 119a04d: Downgrading three and reusing own GLTFLoader and DRACOLoader implementations
21
+ - 89e0c7a: Updated dependencies
22
+ - 16e75c31: Fixed a bug where the suspense was created in the wrong place when preloading was activated.
23
+ - da70d570: typo
24
+ - 81834dd4: Refactored the pascal case function
25
+ - 124eabab: Fixed preload method to return a Promise
26
+ - 89710f3: Removed logs
27
+
28
+ ## 1.0.0-next.13
29
+
30
+ ### Major Changes
31
+
32
+ - 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.
33
+
34
+ ## 1.0.0-next.12
35
+
36
+ ### Patch Changes
37
+
38
+ - 6d56d11c: Added proper types for new slots error & fallback
39
+
40
+ ## 1.0.0-next.11
41
+
42
+ ### Minor Changes
43
+
44
+ - e91cc094: await instead of if clause for less if-blocks (helps with transitions)
45
+
46
+ ## 1.0.0-next.10
47
+
48
+ ### Minor Changes
49
+
50
+ - 05d91701: Added forwarding event handlers
51
+
52
+ ## 1.0.0-next.9
53
+
54
+ ### Patch Changes
55
+
56
+ - 89710f3e: Removed logs
57
+
3
58
  ## 1.0.0-next.8
4
59
 
5
60
  ### Patch Changes
@@ -1,6 +1,39 @@
1
- A small command-line tool that turns GLTF assets into declarative and re-usable [Threlte](https://threlte.xyz) components.
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
- ### The GLTF workflow on the web is not ideal ...
16
+ <a href="https://threlte.xyz">
17
+ <img src="./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
- ### @threlte/gltf fixes that
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
- - Nodejs must be installed
246
- - The GLTF file has to be present in your projects `/public` folder
247
- - [three](https://github.com/mrdoob/three.js/) (>= 122.x)
248
- - @threlte/core > 5.0.0
249
- - @threlte/core > 4.9.3
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
+ [![Powered by Vercel](./assets/vercel/powered-by-vercel.svg)](https://vercel.com/?utm_source=threlte&utm_campaign=oss)
299
+
300
+ ---
250
301
 
251
- ## Credits
302
+ ### License
252
303
 
253
- This tool started off as a fork of [gltfjsx](https://github.com/pmndrs/gltfjsx) by [pmndrs](https://pmnd.rs/).
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.0-next.8",
3
+ "version": "1.0.0",
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": "rm -rf node_modules"
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 getRelativeFilePath(file) {
29
- const filePath = path.resolve(file)
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,23 +44,14 @@ export default function (file, output, options) {
48
44
  }
49
45
  resolve()
50
46
 
51
- const filePath = getRelativeFilePath(file)
47
+ const filePath = getFilePath(file)
52
48
  const data = fs.readFileSync(file)
53
49
  const arrayBuffer = toArrayBuffer(data)
54
- console.log(arrayBuffer)
55
-
56
- gltfLoader.parse(
57
- arrayBuffer,
58
- '',
59
- (gltf) => {},
60
- (error) => console.error(error)
61
- )
62
50
 
63
51
  gltfLoader.parse(
64
52
  arrayBuffer,
65
53
  '',
66
54
  (gltf) => {
67
- console.log('NO PARSE?')
68
55
  const raw = parse(filePath, gltf, options)
69
56
  try {
70
57
  const prettiered = prettier.format(raw, {
@@ -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 = (fileName.toLowerCase().startsWith('http') ? '' : '/') + fileName
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={$gltf.${node}.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={$gltf.materials${sanitizeName(obj.material.name)}} `
159
- else result += `material={$gltf.${node}.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={$gltf.${node}.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={$gltf.${node}.morphTargetDictionary} `
167
+ result += `morphTargetDictionary={gltf.${node}.morphTargetDictionary} `
168
168
  if (obj.morphTargetInfluences)
169
- result += `morphTargetInfluences={$gltf.${node}.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={$gltf.${node}} />\n`
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
- ${options.types && !options.isolated ? 'type $$Slots = Slots<THREE.Group>' : ''}
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
- {#if $gltf}
558
- ${scene}
559
- {/if}
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>
Binary file