Skip to content

Commit e1eecdf

Browse files
authored
Zero Config Draco Support (#171)
* Initialize Draco decoder in use-asset hooks for improved asset loading performance * Add Draco decoding support to useModel hook in documentation - Introduced a section on Draco decoding in the use-asset documentation. - Explained how to utilize the built-in Draco decoder and provided an example for self-hosting the library. - Updated documentation to enhance clarity on asset loading capabilities.
1 parent be95a9a commit e1eecdf

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

packages/docs/components/hooks/use-asset.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
"use client";
22

3-
import { TEXTURETYPE_RGBP } from "playcanvas"
3+
import { dracoInitialize, TEXTURETYPE_RGBP } from "playcanvas"
44
import { useApp } from "@playcanvas/react/hooks"
55
import { useQuery } from "@tanstack/react-query";
66
import { fetchAsset } from "@playcanvas/react/utils"
77

8+
const base = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/";
9+
dracoInitialize({
10+
jsUrl: base + 'draco_wasm_wrapper.js',
11+
wasmUrl: base + 'draco_decoder.wasm',
12+
numWorkers: 2,
13+
lazyInit: true
14+
});
15+
816
/**
917
* Loads an asset using react-query
1018
*

packages/docs/content/docs/api/hooks/use-asset.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ export function RenderModel() {
102102
}
103103
```
104104

105+
### Draco Decoding
106+
107+
The `useModel` hook also supports Draco decoding out of the box without zero configuration. @playcanvas/react will use the latest version of the Draco decoder ([1.5.7](https://github.com/google/draco?tab=readme-ov-file#version-157-release)) and lazy load it from the Google CDN.
108+
109+
Alternatively if you want to self-host the library you can manually configure the decoder using `dracoInitialize`.
110+
111+
```tsx copy filename="render-draco.tsx"
112+
import { dracoInitialize } from 'playcanvas';
113+
114+
dracoInitialize({
115+
jsUrl: '/draco_decoder.js',
116+
wasmUrl: '/draco_decoder.wasm',
117+
lazyInit: true
118+
});
119+
```
120+
105121
## useSplat
106122

107123
A specialized hook for loading Gaussian Splat assets. Pass the source URL of the splat file and any additional properties to pass to the asset loader and use the resulting asset in the [`<GSplat/>`](/docs/api/components/GSplat) component.

packages/lib/src/hooks/use-asset.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { useState, useEffect, useRef, useCallback } from "react";
22
import { fetchAsset, AssetMeta } from "../utils/fetch-asset";
33
import { useApp } from "./use-app";
4-
import { Asset, TEXTURETYPE_RGBP } from "playcanvas";
4+
import { Asset, dracoInitialize, TEXTURETYPE_RGBP } from "playcanvas";
55
import { warnOnce } from "../utils/validation";
66

7+
const base = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/";
8+
dracoInitialize({
9+
jsUrl: base + 'draco_wasm_wrapper.js',
10+
wasmUrl: base + 'draco_decoder.wasm',
11+
numWorkers: 2,
12+
lazyInit: true
13+
});
14+
715
/**
816
* Supported asset types that can be loaded
917
*/

0 commit comments

Comments
 (0)