@gamewall/threejs 1.0.1 → 1.1.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,7 +61,7 @@ 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
@@ -99,7 +99,7 @@ It is also asynchronous because GLTF loading may involve fetching multiple resou
99
99
 
100
100
  > ℹ️ 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
101
  > ```bash
102
- > gltfpack -c -tc -tp -kn -km -i input.glb -o output.glb
102
+ > gltfpack -c -tc -tp -kn -km -noq -i input.glb -o output.glb
103
103
  > ```
104
104
  >
105
105
  > - `-c` enables mesh compression with Meshopt
@@ -107,5 +107,24 @@ It is also asynchronous because GLTF loading may involve fetching multiple resou
107
107
  > - `-tp` converts textures to power-of-two dimensions for better GPU compatibility
108
108
  > - `-kn` keeps the names in the model to allow modifying specific nodes
109
109
  > - `-km` keeps the material names in the model to allow modifying specific materials
110
+ > - `-noq` keeps original UV coordinates, to allow for retexturing
110
111
  >
111
112
  > On average, you should see around 70-80% size reduction compared to uncompressed GLTF/GLB files.
113
+
114
+ ### `async loadTexture(name: string): Promise<THREE.Texture>`
115
+
116
+ Loads a standard texture (PNG, JPEG, etc.) from the GameWall assets. Convenience wrapper around ThreeJS's TextureLoader.
117
+
118
+ - `name` is the filename of the texture file in the GameWall assets folder.
119
+
120
+ ```typescript
121
+ import * as THREE from 'three';
122
+ import { loadTexture } from '@gamewall/threejs';
123
+
124
+ async function loadStandardTexture() {
125
+ const texture = await loadTexture('sponsorLogo.png');
126
+ const material = new THREE.MeshStandardMaterial({ map: texture }); // Use the loaded texture
127
+ }
128
+ ```
129
+
130
+ > ℹ️ 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.1.0",
4
4
  "description": "ThreeJS utils for GameWall",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
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
+ }