gpt4 book ai didi

javascript - 如何加载特定模板的 Three.js

转载 作者:行者123 更新时间:2023-11-27 23:56:37 25 4
gpt4 key购买 nike

我知道将外部库加载到 meteor 中的两种主要方法(如 http://www.manuel-schoebel.com/blog/use-meteor-iron-router-waiton-to-load-external-javascript 中所讨论的)。

此外,还有用于加载 Three.js 全局的meteor包。

有人知道如何使用模板级方法来让THREE工作吗?我不希望 two.js 加载到所有路由上,但到目前为止我尝试使用 ~

Template.threeview.onRendered(function(){

Session.setDefault('threejs', false);
// is library already loaded?
if (Session.get('threejs') === false) {
console.log('Requesting threejs...')
$.getScript('/js/three.min.js', function() {
Session.set('threejs', true);
// the THREE object should now be accessible here
// as well as in the window environment...?
console.log(window.THREE);
console.log(THREE);
});
};
});

不起作用 - 我明白

undefined 
Uncaught ReferenceError: THREE is not defined

在 js 控制台窗口中。

有什么想法吗?

编辑

发现这个类似的问题Can't find three.js after loading through Ajax遇到同样的问题 - 我可以确认从 CDN 加载是有效的。有人有更好的解决方案吗?

最佳答案

终于想通了 - 实现这一点的方法是编辑 two.min.js 源文件。在 two.min.js 开头删除/注释 'use strict'; 可以使其正确加载。

这似乎与 Meteor 的以下功能/问题有关:https://github.com/meteor/meteor/issues/1380

CDN 未缩小且不包含“use strict;”。为了安全起见,'use strict;' 可能应该放置在声明全局 THREE 命名空间之后。

关于javascript - 如何加载特定模板的 Three.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32208153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com