首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在google web应用程序脚本中使用three.js -无法使用脚本模块类型加载three.js

在google web应用程序脚本中使用three.js -无法使用脚本模块类型加载three.js
EN

Stack Overflow用户
提问于 2021-01-14 02:15:39
回答 1查看 275关注 0票数 1

我想在google脚本中使用three.js来加载三维CAD文件,而在threejs.org上的安装说明中它解释了脚本需要“模块”类型。同时,在我搜索了几天之后,谷歌的web应用程序脚本似乎不支持“模块”。

有没有人用过three.js作为谷歌脚本?非常感谢你分享你的经验。否则,我必须放弃我的想法,加载CAD数据的网页应用程序,我正在建设。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-14 10:06:07

应用程序脚本不支持模块

来自:语法

警告:ES6模块还不受支持。

但是,您可以像调用jQuery这样的库一样调用脚本。

代码语言:javascript
复制
<script src="https://threejs.org/build/three.js"></script>

Web应用示例

Code.gs

代码语言:javascript
复制
function doGet(){
 HTMLOutput = HtmlService.createHtmlOutputFromFile('index.html')
 return HTMLOutput
}

index.html

代码语言:javascript
复制
<!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应用程序时,我得到了以下结果:

参考文献

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65712464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档