@needle-tools/materialx 1.1.0-next.0aa8b46 → 1.1.0-next.899791c
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 +17 -3
- package/index.ts +1 -1
- package/needle.ts +1 -1
- package/package.json +1 -1
- package/src/loader/loader.needle.ts +3 -3
- package/src/loader/loader.three.ts +2 -2
package/README.md
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
# Needle MaterialX
|
|
2
2
|
|
|
3
|
-
Web runtime support to load and display MaterialX materials in Needle Engine
|
|
3
|
+
Web runtime support to load and display MaterialX materials in Needle Engine and three.js
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
`npm i @needle-tools/materialx`
|
|
7
7
|
|
|
8
|
+
## Examples
|
|
9
|
+
- [three.js Example on Stackblitz](https://stackblitz.com/edit/needle-materialx-example?file=main.js,package.json,index.html)
|
|
10
|
+
|
|
8
11
|
## How to use
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
### Use with Needle Engine
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { useNeedleMaterialX } from "@needle-tools/materialx/needle";
|
|
17
|
+
// Simply call this function in global scope as soon as possible
|
|
18
|
+
useNeedleMaterialX();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Use with three.js
|
|
11
22
|
|
|
12
23
|
```ts
|
|
13
|
-
import "@needle-tools/materialx"
|
|
24
|
+
import { useNeedleMaterialX } from "@needle-tools/materialx";
|
|
25
|
+
// Call the function with your GLTFLoader instance
|
|
26
|
+
useNeedleMaterialX(<yourGltfLoaderInstance>);
|
|
14
27
|
```
|
|
15
28
|
|
|
29
|
+
|
|
16
30
|
<br />
|
|
17
31
|
|
|
18
32
|
# Contact ✒️
|
package/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./src/index.js";
|
|
2
|
-
export {
|
|
2
|
+
export { useNeedleMaterialX } from "./src/loader/loader.three.js";
|
package/needle.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./src/index.js";
|
|
2
|
-
export {
|
|
2
|
+
export { useNeedleMaterialX } from "./src/loader/loader.needle.js";
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { addCustomExtensionPlugin } from "@needle-tools/engine";
|
|
|
2
2
|
import { Context, GLTF, INeedleGLTFExtensionPlugin } from "@needle-tools/engine";
|
|
3
3
|
import type { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
4
|
import type { GLTFExporter } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useNeedleMaterialX as _useNeedleMaterialX, MaterialXLoader } from "./loader.three.js";
|
|
6
6
|
import { debug } from "../utils.js";
|
|
7
7
|
import { MaterialParameters } from "three";
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ export class MaterialXLoaderPlugin implements INeedleGLTFExtensionPlugin {
|
|
|
14
14
|
|
|
15
15
|
onImport = (loader: GLTFLoader, url: string, context: Context) => {
|
|
16
16
|
if (debug) console.log("MaterialXLoaderPlugin: Registering MaterialX extension for", url);
|
|
17
|
-
|
|
17
|
+
_useNeedleMaterialX(loader, {
|
|
18
18
|
cacheKey: url,
|
|
19
19
|
parameters: {
|
|
20
20
|
precision: context.renderer.capabilities.getMaxPrecision("highp") as MaterialParameters["precision"],
|
|
@@ -38,6 +38,6 @@ export class MaterialXLoaderPlugin implements INeedleGLTFExtensionPlugin {
|
|
|
38
38
|
/**
|
|
39
39
|
* Add the MaterialXLoaderPlugin to the Needle Engine.
|
|
40
40
|
*/
|
|
41
|
-
export async function
|
|
41
|
+
export async function useNeedleMaterialX() {
|
|
42
42
|
addCustomExtensionPlugin(new MaterialXLoaderPlugin());
|
|
43
43
|
}
|
|
@@ -309,9 +309,9 @@ export class MaterialXLoader implements GLTFLoaderPlugin {
|
|
|
309
309
|
|
|
310
310
|
|
|
311
311
|
/**
|
|
312
|
-
* Add the
|
|
312
|
+
* Add the MaterialXLoader to the GLTFLoader instance.
|
|
313
313
|
*/
|
|
314
|
-
export function
|
|
314
|
+
export function useNeedleMaterialX(loader: GLTFLoader, options?: MaterialXLoaderOptions, context?: MaterialXContext) {
|
|
315
315
|
loader.register(p => {
|
|
316
316
|
const loader = new MaterialXLoader(p, options || {}, context || {});
|
|
317
317
|
return loader;
|