宣言
const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array([
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0,
1.0, 1.0, 0.0,
-1.0, 1.0, 0.0
]);
geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
const indices = new Uint16Array([
0, 1, 2,
0, 2, 3
]);
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
const material = new THREE.MeshBasicMaterial({color: 0xff0000, side: THREE.DoubleSide});
const rectangle = new THREE.Mesh(geometry, material);
scene.add(rectangle);
動的に変更
function animate() {
requestAnimationFrame(animate);
const time = performance.now() * 0.001;
const amplitude = 0.5;
const frequency = 1.0;
for (let i = 0; i < vertices.length / 3; i++) {
vertices[i * 3 + 1] = Math.sin(time * frequency + i) * amplitude;
}
geometry.attributes.position.needsUpdate = true;
rectangle.rotation.x += 0.01;
rectangle.rotation.y += 0.01;
renderer.render(scene, camera);
}