我有一个用例,我试图加载一个使用DRACO-Compression压缩的GLTF文件。我可以使用普通JavaScript运行它,但我面临着将加载程序与ReactJs集成的问题。
我在做什么:
- 将draco库从此处复制到应用程序的作用域-https://github.com/mrdoob/three.js/tree/master/examples/js/libs/draco
- 将DRACOLoader.js从此处复制到应用程序的作用域-https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/DRACOLoader.js
- 将其作为THREE.DRACOLoader模块导出到应用程序中需要它的位置
我得到的错误-DracoDecoderModule未定义
在我的应用程序中,这是我导入的方式:
import DRACOLoader from './DRACOLoader'
DRACOLoader.setDecoderPath('./draco/')
8条答案
按热度按时间mutmk8jj1#
建议使用https://www.gstatic.com/draco/v1/decoders/作为解码器源目录,例如:
参见示例https://github.com/google/draco/tree/master/javascript/example。
x6492ojm2#
相对路径不起作用,一种方法是把你的
draco_wasm_wrapper.js
托管在aws之类的平台上,或者你可以尝试以下方法:导入依赖项:
创建并配置您的draco装载机:
创建并配置gltf加载程序:
bcs8qyzn3#
我喜欢@marrion luaka的答案(并投了赞成票),但参考了当地的情况。
仅变更:
对此:
dracoLoader.setDecoderPath( '../node_modules/three/examples/js/libs/draco/gltf/' );
du7egjpx4#
在云中托管draco文件夹,然后
对我有用。
如果你真喜欢这个,
那么react会把它当作,
所以行不通。
pdsfdshx5#
上面的代码都不能直接在three@0.115.0上运行,所以我使用了:
对于那些喜欢承诺的人,我也一直在让我的装载机返回以下承诺:
示例用法:
然后在其他地方:
zz2j4svz6#
也许是另一种选择(仅适用于
React
)。我将这三个必需的文件从node_modules复制到public中一个名为'draco'的文件夹中。
nwnhqdif7#
我使用Webpack的方式与Create React App使用它的方式类似。下面是我如何让Draco解码器路径工作的。
1.在应用的
public
文件夹中,创建名为draco
的新文件夹。1.下载Three.js Draco Examples中的四个文件,并将它们移动到
public/draco
文件夹中。1.使用此代码:
of1yzvn48#
建议使用https://www.gstatic.com/draco/versioned/decoders/[version]/作为解码器源目录,例如:
如此处所述,自
v1.4.1
以来,建议使用版本化的www.gstatic.com
WASM和Javascript解码器。