简体   繁体   English

使用require.js加载XML3D

[英]Loading XML3D with require.js

XML3D doesn't work with require.js even if one make sure its loaded first and use " shim " configuration option (for non-AMD modules). 即使确保首先加载XML3D并使用“ shim ”配置选项(对于非AMD模块),XML3D也无法与require.js一起使用。

I've following code: 我下面的代码:

index.html that contains xml3d tags 包含xml3d标记的index.html

<xml3d>
...some stuff..
</xml3>
<script data-main="scripts/main.js" src="scripts/require.js"></script>

main.js main.js

requirejs.config({
  paths: {
    xml3d: *url*
  },
  shim: {
    'xml3d': { exports: 'XML3D' }
  }
});

requirejs(['xml3d'], function (XML3D) { console.log(XML3D) // that works });

The console.log code shows proper info, however the XML3D canvas isn't properly opened (its shrinked to small area and no objects are rendered). console.log代码显示正确的信息,但是XML3D画布没有正确打开(它缩小到很小的区域,并且没有呈现任何对象)。

And, Yes putting 而且,是的

 <script src="xml3D url"></script>

instead using require.js works OK (everything is rendered.) So this code below works (composed of index.html without main.js ). 而是使用require.js可以正常工作(呈现所有内容。)因此,下面的这段代码可以工作(由index.html组成,不带main.js )。

<xml3d>
...some stuff..
</xml3>
<script src="url of XML3D"></script>

You're right, this was a simple oversight in the way XML3D is initialized. 没错,这是对XML3D初始化方式的简单监督。 We were registering a listener for DOMContentLoaded without checking the document.readyState first, so logically by the time require.js had loaded XML3D the DOMContentLoaded event had already been dispatched. 我们正在为DOMContentLoaded注册一个侦听器,而不先检查document.readyState ,因此从逻辑上讲,在require.js加载XML3D时,已经调度了DOMContentLoaded事件。

The fix will be part of the upcoming 4.9.4 release and is sitting on the hotfix-4.9.4 branch . 该修复程序将是即将发布的4.9.4版本的一部分,位于hotfix-4.9.4分支上

There's no easy workaround in the mean time (unless you want to fire the DOMContentLoaded event manually after XML3D has been loaded through require.js, which is pretty messy) but you could either build the hotfix branch or pull the fix into your copy of xml3d.js since it's only a couple of lines. 在此期间,没有简单的解决方法(除非您要在通过require.js加载XML3D之后手动触发DOMContentLoaded事件,这很麻烦),但是您可以构建修补程序分支或将修补程序拉入xml3d副本中.js,因为它只有几行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM