gpt4 book ai didi

javascript - 引用错误 : THREE is not defined

转载 作者:行者123 更新时间:2023-11-30 14:02:15 24 4
gpt4 key购买 nike

我正在尝试从三个(节点模块)中导入 SSAO 着色器:

import {SSAOShader} from 'three/examples/js/shaders/SSAOShader'` 

但我得到:

ReferenceError: THREE is not defined
./node_modules/three/examples/js/shaders/SSAOShader.js
node_modules/three/examples/js/shaders/SSAOShader.js:9
6 | * https://learnopengl.com/Advanced-Lighting/SSAO
7 | *
8 | */
> 9 | THREE.SSAOShader = {
10 | defines: {
11 | "PERSPECTIVE_CAMERA": 1,
12 | "KERNEL_SIZE": 32

链接到jsm文件没有问题,但是链接到js文件会抛出错误。

import React, { Component } from 'react';
import * as THREE from 'three';
import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader';
import {OBJLoader} from 'three/examples/jsm/loaders/OBJLoader';
import {SSAOShader} from 'three/examples/js/shaders/SSAOShader';

希望能够在不抛出错误的情况下使用这个库。

最佳答案

import {SSAOShader} from 'three/examples/js/shaders/SSAOShader';

这行代码无效,因为 SSAOShader 不是模块。现在,您必须自己将文件转换为模块。稍后,SSAOShader 的模块版本将在 jsm 目录中可用。

three.js R104

关于javascript - 引用错误 : THREE is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56132698/

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