首页 > 解决方案 > 在组件内部的Aframe中导入threejs代码

问题描述

我正在尝试使用threejs 代码创建框架组件。如何在a-frame组件中集成threejs模块?请指导我,我正在努力寻找解决方案。我正在尝试将其集成到我的组件中


<script type="module">
    AFRAME.registerComponent('navigation-controls', {
    init: function(){
        let el = this.el;
        import * as THREE from 'https://raw.githubusercontent.com/mrdoob/three.js/dev/build/three.module.js'
        import { IndoorControls } from 'https://raw.githack.com/wobushijiujiu/three.js/dev/examples/jsm/controls/IndoorControls.js';
        // tried this using outside of the component if was not working there also
       let scene = document.querySelector("a-scene");
        let camera = scene.camera;
        let renderer = scene.renderer;
        let groundControls = new IndoorControls( camera, renderer.domElement );
       console.log(groundControls); //this is showing error - IndoorControls not found
     }
});

标签: three.jsaframe

解决方案


A-Frame 原生包含 Three.js,因此 THREE 对象是全局可用的,无需包含其他任何内容。


推荐阅读