@gamewall/threejs 1.0.1 → 1.2.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/README.md CHANGED
@@ -61,12 +61,12 @@ This function is asynchronous because KTX2 textures may require transcoding, whi
61
61
 
62
62
  > ℹ️ Note: You can use [KTX-Software](https://github.com/KhronosGroup/KTX-Software) to convert your textures to KTX2 format with the following command:
63
63
  > ```bash
64
- > toktx2 --t2 --bcmp output.ktx2 input.png
64
+ > toktx --t2 --bcmp output.ktx2 input.png
65
65
  > ```
66
66
  > - `--t2` ensures the texture is in KTX2 format
67
67
  > - `--bcmp` applies Basis Universal supercompression
68
68
 
69
- ### `async loadGltf(name: string, renderer: THREE.WebGLRenderer): Promise<[THREE.Object3D, { [name: string]: THREE.MeshPhysicalMaterial }]>`
69
+ ### `async loadGltf(name: string, renderer: THREE.WebGLRenderer): Promise<[THREE.Object3D, { [name: string]: THREE.MeshPhysicalMaterial }, GLTF]>`
70
70
 
71
71
  Loads a GLTF/GLB model from the GameWall assets, with support for KTX2 and Meshopt.
72
72
 
@@ -89,7 +89,13 @@ async function loadModel() {
89
89
  }
90
90
  ```
91
91
 
92
- This function returns a touple containing the loaded model (as a THREE.Object3D) and a dictionary of materials by their names. This allows you to easily modify specific materials after loading.
92
+ This function returns a touple containing
93
+
94
+ - the loaded model (as a THREE.Object3D),
95
+ - a dictionary of materials by their names, and
96
+ - the full GLTF object.
97
+
98
+ This allows you to easily access the 3D object and modify specific materials after loading and access other GLTF data. For advanced use cases, like modifying animations or accessing specific nodes, you can use the GLTF object directly.
93
99
 
94
100
  > ⚠️ Warning: The returned materials dictionary only includes PBR materials (MeshPhysicalMaterial). Please make sure your 3D modeling tool exports materials in this format for compatibility. If you use Blender, the default "Principled BSDF" shader corresponds to MeshPhysicalMaterial in ThreeJS.
95
101
 
@@ -99,7 +105,7 @@ It is also asynchronous because GLTF loading may involve fetching multiple resou
99
105
 
100
106
  > ℹ️ Note: you can use [gltfpack](https://meshoptimizer.org/gltf/) to compress your GLTF models with Meshopt and KTX2 for optimal performance and size with the following command:
101
107
  > ```bash
102
- > gltfpack -c -tc -tp -kn -km -i input.glb -o output.glb
108
+ > gltfpack -c -tc -tp -kn -km -noq -i input.glb -o output.glb
103
109
  > ```
104
110
  >
105
111
  > - `-c` enables mesh compression with Meshopt
@@ -107,5 +113,24 @@ It is also asynchronous because GLTF loading may involve fetching multiple resou
107
113
  > - `-tp` converts textures to power-of-two dimensions for better GPU compatibility
108
114
  > - `-kn` keeps the names in the model to allow modifying specific nodes
109
115
  > - `-km` keeps the material names in the model to allow modifying specific materials
116
+ > - `-noq` keeps original UV coordinates, to allow for retexturing
110
117
  >
111
118
  > On average, you should see around 70-80% size reduction compared to uncompressed GLTF/GLB files.
119
+
120
+ ### `async loadTexture(name: string): Promise<THREE.Texture>`
121
+
122
+ Loads a standard texture (PNG, JPEG, etc.) from the GameWall assets. Convenience wrapper around ThreeJS's TextureLoader.
123
+
124
+ - `name` is the filename of the texture file in the GameWall assets folder.
125
+
126
+ ```typescript
127
+ import * as THREE from 'three';
128
+ import { loadTexture } from '@gamewall/threejs';
129
+
130
+ async function loadStandardTexture() {
131
+ const texture = await loadTexture('sponsorLogo.png');
132
+ const material = new THREE.MeshStandardMaterial({ map: texture }); // Use the loaded texture
133
+ }
134
+ ```
135
+
136
+ > ℹ️ Note: This works with image properties in the `configurables` section of your manifest too.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamewall/threejs",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "ThreeJS utils for GameWall",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/src/gltf.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as THREE from 'three'
2
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
2
+ import { GLTFLoader, GLTF } from 'three/addons/loaders/GLTFLoader.js'
3
3
  import { getBuffer } from 'gamewall'
4
4
  import { extractBuffer } from './utils'
5
5
 
@@ -19,7 +19,7 @@ export function getGltfLoader(renderer: THREE.WebGLRenderer): GLTFLoader {
19
19
  return loader;
20
20
  }
21
21
 
22
- export async function loadGltf(url: string, renderer: THREE.WebGLRenderer): Promise<[THREE.Object3D, { [name: string]: THREE.MeshPhysicalMaterial }]> {
22
+ export async function loadGltf(url: string, renderer: THREE.WebGLRenderer): Promise<[THREE.Object3D, { [name: string]: THREE.MeshPhysicalMaterial }, GLTF]> {
23
23
  const glbBuffer = extractBuffer(getBuffer(url));
24
24
  const gltfLoader = getGltfLoader(renderer);
25
25
 
@@ -52,5 +52,5 @@ export async function loadGltf(url: string, renderer: THREE.WebGLRenderer): Prom
52
52
  }
53
53
  });
54
54
 
55
- return [result, Object.fromEntries(materials)];
55
+ return [result, Object.fromEntries(materials), gltf];
56
56
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { getExr } from './exr';
2
2
  export { loadKtx2 } from './ktx2';
3
3
  export { loadGltf } from './gltf';
4
+ export { loadTexture } from './texture';
package/src/texture.ts ADDED
@@ -0,0 +1,19 @@
1
+ import * as THREE from 'three';
2
+ import { getUrl } from 'gamewall';
3
+
4
+ let loader: THREE.TextureLoader | null = null;
5
+
6
+ export function getTextureLoader(): THREE.TextureLoader {
7
+ if (!loader) {
8
+ loader = new THREE.TextureLoader();
9
+ }
10
+ return loader;
11
+ }
12
+
13
+ export async function loadTexture(url: string): Promise<THREE.Texture> {
14
+ const textureLoader = getTextureLoader();
15
+
16
+ return new Promise<THREE.Texture>((resolve, reject) => {
17
+ textureLoader.load(getUrl(url), resolve, undefined, reject);
18
+ });
19
+ }