Why do some obj files loaded by text load indefinitely?

I am loading obj file contents from a GitHub repository so I can swap out links and load new content into my online shop, my problem is some of the obj files completely fail to load without any errors in console, they just don’t show up and the loading screen doesn’t go away until I .dispose() of them. Here is my code, any help would be appreciated!

function importMesh(modelURL,albedoURL,rougnessURL){
	var betterurl = loadPage(modelURL);
	betterurl = betterurl.substring(betterurl.indexOf("\n") + 1);
	betterurl = betterurl.substring(betterurl.indexOf("\n") + 1);
	//betterurl = betterurl.substring(betterurl.indexOf("\n") + 1);
	var myreturn;
	BABYLON.SceneLoader.Append("", 'data:' + betterurl , scene, function (scenereturn) {

		let scale = 0.18;

		var hatmeshmaterial = new BABYLON.StandardMaterial("", scene);
		hatmeshmaterial.diffuseTexture = new BABYLON.Texture(albedoURL, scene);
		hatmeshmaterial.specularTexture = new BABYLON.Texture(rougnessURL, scene);
		scenereturn.meshes[scenereturn.meshes.length -1].scaling.x = scale;
		scenereturn.meshes[scenereturn.meshes.length -1].scaling.y = scale;
		scenereturn.meshes[scenereturn.meshes.length -1].scaling.z = scale;
		scenereturn.meshes[scenereturn.meshes.length -1].position.y = -1;
		scenereturn.meshes[scenereturn.meshes.length -1].material = hatmeshmaterial;

		previewhats.push(scenereturn.meshes[scenereturn.meshes.length -1]);

Through deciding to post this I immediately solved my problem by analyzing my hesitation to include the urls that get loaded in the albedoURL and rougnessURL but still posted anyways so I can help anyone else in this situation. While thinking whether it was necasery or not i realized that the roughness URL may be undefined because not all of my resources are mapped to a roughness url. So my solution was changing

hatmeshmaterial.specularTexture = new BABYLON.Texture(rougnessURL, scene);

to be

    hatmeshmaterial.specularTexture = new BABYLON.Texture(rougnessURL, scene);

Basically its important if your loading textures in a model loading on success callback you need to ensure they aren’t undefined or null otherwise no errors will be thrown and you’ll be scratching your head for hours

1 Like