我想在google脚本中使用three.js来加载三维CAD文件,而在threejs.org上的安装说明中它解释了脚本需要“模块”类型。同时,在我搜索了几天之后,谷歌的web应用程序脚本似乎不支持“模块”。
有没有人用过three.js作为谷歌脚本?非常感谢你分享你的经验。否则,我必须放弃我的想法,加载CAD数据的网页应用程序,我正在建设。
<script type="module">
// Find the latest version by visiting https://unpkg.com/three. The URL will
// redirect to the newest stable release.
import * as THREE from 'https://unpkg.com/three/build/three.module.js';
const scene = new THREE.Scene();
</script>发布于 2021-01-14 10:06:07
应用程序脚本不支持模块
来自:语法
警告:ES6模块还不受支持。
但是,您可以像调用jQuery这样的库一样调用脚本。
<script src="https://threejs.org/build/three.js"></script>Web应用示例
Code.gs
function doGet(){
HTMLOutput = HtmlService.createHtmlOutputFromFile('index.html')
return HTMLOutput
}index.html
<!DOCTYPE html>
<html>
<head>
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script src="https://threejs.org/build/three.js"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
const animate = function () {
requestAnimationFrame( animate );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
};
animate();
</script>
</body>
</html>改编自:https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene
结果
当将它部署为Web应用程序时,我得到了以下结果:

参考文献
https://stackoverflow.com/questions/65712464
复制相似问题