I am facing an issue with my function that is supposed to create a 3D object (a planet) using orbital parameters and texture images from a dataset. Strangely, the textures are not rendering when I use StandardMaterial or PhongMaterial, even though they work fine with BasicMaterial. I have already verified that the textures work outside of the loop and function. I am unsure of what else to try. Below is the code snippet:
for(var i=0;i < results.data.length; i++){
const EC = Number(results.data[i]["Eccentricity"]); //Eccentricity
const IN = Number(results.data[i]["Inclination [Rad]"]) ; //Inclination
const OM = Number(results.data[i]["Orbit Rotation_Y [Rad]"]) ; //Longitude of ascending node
const W = Number(results.data[i]["Orbit Rotation_X [Rad]"]); //Argument of periapsis
const A = Number(results.data[i]["Orbit semi-major axis [UA]"]); //Semi-major axis
const EcRadius = Number(results.data[i]["Relative Equatorial Radius"]); //Radius
const NAM = results.data[i]["Name"]; //Name
const textureUrl = results.data[i]["TextureFileUrl"]; //Texture image of the planet
const loader = new THREE.TextureLoader();
loader.load(textureUrl, function ( texture ) {
// Create the material when the texture is loaded
var tex = texture.clone();
const PlanetMaterial = new THREE.MeshBasicMaterial( {
map: tex
} );
scene.add(CreatePlanet( 0,0,0, EC,IN,OM,W,A,EcRadius, NAM, 0x4E4E4E, 0.5, PlanetMaterial ));
},
undefined,
function ( err ) {
console.error( 'An error happened.');
}
);
}
The CreatePlanet
function simply creates a mesh with the given material, like so:
const geometryPlanet = new THREE.SphereBufferGeometry(EcRadius, 300, 300);
const Planet = new THREE.Mesh(geometryPlanet, PlanetMaterial);
return Planet;
Any help on this matter would be greatly appreciated. Thank you.