Hi guys,
I’m npm installed three.js version 147 and simplex noise version 4.0.0 for my vue project.
However, I keep getting error: TypeError: THREE.SimplexNoise is not a constructor
This is the code:
import * as THREE from "three";
import {SimplexNoise} from "three/examples/jsm/math/SimplexNoise"
const renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x161d31);
const camera = new THREE.PerspectiveCamera(100, window.innerWidth / window.innerHeight, 0.1, 10000);
camera.position.set(120, 0, 300);
const light = new THREE.HemisphereLight(0xffffff, 0x0c056d, 0.6);
scene.add(light);
const light1 = new THREE.DirectionalLight(0x590d82, 0.5);
light1.position.set(100, 300, 400);
scene.add(light1);
const light2 = light1.clone();
light2.position.set(-100, 300, 400);
scene.add(light2);
const material = new THREE.MeshLambertMaterial({
emissive: 0x23f660,
emissiveIntensity: 0.4
});
const geometry = new THREE.IcosahedronGeometry(120, 12);
const positionAttributeBase = geometry.getAttribute( 'position' ).clone();
const shape = new THREE.Mesh(geometry, material);
scene.add(shape);
const simplex = new THREE.SimplexNoise();
const vector = new THREE.Vector3();
function updateVertices(time) {
const positionAttribute = geometry.getAttribute('position');
for (let i = 0; i < positionAttributeBase.count; i++) {
vector.fromBufferAttribute(positionAttributeBase, i);
const noise = simplex.noise3d(
vector.x * 0.006 + time * 0.0002,
vector.y * 0.006 + time * 0.0003,
vector.z * 0.006
);
const ratio = noise * 0.4 + 0.9;
vector.multiplyScalar(ratio);
positionAttribute.setXYZ(i, vector.x, vector.y, vector.z)
}
positionAttribute.needsUpdate = true;
}
function animate(time=0) {
requestAnimationFrame(animate);
updateVertices(time);
renderer.render(scene, camera);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
animate();
How could I resolve this??
Thanks!