我有一个 p5.js 脚本,它绘制了一个 perlin noise Canva,稍后我将其转换为一个变量。然后我需要将该变量导入到 THREE.js 文件中以用作纹理。它返回一个错误,说我导出的变量没有定义。
我使用了“export { variable };”在 p5.js 脚本中,它返回一个错误,指出未定义导出。在第二个文件中,我使用“import { variable } from './filename.js' }; 它返回一个错误,指出另一个文件中的变量未定义。
第一个文件(使用 p5.js):
function setup() {
createCanvas(800, 400);
noStroke();
for (var x = 0; x < width; x+=1) {
for (var y = 0; y < height; y+=1) {
var c = 255 * noise(0.01 * x, 0.01 * y);
fill(c);
rect(x, y, 10, 10);
}
}
//return image from canvas
//(gets the entire image when it is not specified any parameter)
}
var map = get();
if (map==null) {
console.log("no export");
}
// noprotect
//export { map };
第二个文件(使用 THREE.js):
import { map } from 'http://[...].org/js/perlin.js';