简体   繁体   English

ThreeJs OrbitControl CDN导入版

[英]ThreeJs OrbitControl import version from CDN

I'm using threejs from CDN and i need OrbitControl too, but if I use the same lastest version 0.148.0 to import both Three and OrbitControl it don't work:我正在使用来自 CDN 的 threejs 并且我也需要 OrbitControl,但是如果我使用相同的最新版本 0.148.0 来导入 Three 和 OrbitControl 它不起作用:

import * as THREE from 'https://unpkg.com/three@0.148.0/build/three.module.js'
import {OrbitControls} from 'https://unpkg.com/three@0.148.0/examples/jsm/controls/OrbitControls.js'

To make it work I need to use FOR OrbitControl Only the lower 0.126.1 version为了让它工作,我需要使用 FOR OrbitControl Only the lower 0.126.1 version

import * as THREE from 'https://unpkg.com/three@0.148.0/build/three.module.js'
import {OrbitControls} from 'https://unpkg.com/three@0.126.1/examples/jsm/controls/OrbitControls.js'

WHY is so?为什么会这样? Thank you very much, i'm a total beginnner非常感谢,我是一个初学者

You need an import map when importing latest three.js releases.导入最新的three.js版本时需要导入 map。 Rewrite your imports like so:像这样重写你的导入:

import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

And in your HTML, put this in your header:在您的 HTML 中,将其放入您的 header:

<script type="importmap">
    {
        "imports": {
                "three": "https://unpkg.com/three@0.148.0/build/three.module.js",
                "three/addons/": "https://unpkg.com/three@0.148.0/examples/jsm/"
        }
    }
</script>

In this way, the imports will look exactly like in the official examples.通过这种方式,导入将与官方示例中的完全一样。

The import map will tell the browser how to resolve the bare module specifier three .导入 map 将告诉浏览器如何解析裸模块说明符three More information in the official Installation guide.官方安装指南中的更多信息。

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

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