HI,
Does anyone know if there is a way to load the cell contents of a CSV file into Three.js as an array?
Thank you
HI,
Does anyone know if there is a way to load the cell contents of a CSV file into Three.js as an array?
Thank you
fetch
or XMLHttpRequest
API.Geometry
, Material
, and Mesh
based on the contents of the cells.scene.add
method.var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var data;
// Load the CSV file using fetch
fetch('path/to/file.csv')
.then(response => response.text())
.then(text => {
// Parse the CSV data using Papa Parse
data = Papa.parse(text).data;
// Iterate through the data and create a cube for each row
for (var i = 0; i < data.length; i++) {
var row = data[i];
var cube = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
var mesh = new THREE.Mesh(cube, material);
mesh.position.set(row[0], row[1], row[2]);
scene.add(mesh);
}
});
camera.position.z = 5;
var animate = function () {
requestAnimationFrame( animate );
renderer.render( scene, camera );
};
animate();
Source ChatGPT, “load the cell contents of a CSV file into Three.js”
Brilliant, Thanks for the reply!!!