Loop objloader error

i write a loop to call the objloader and mtlloader, and some of the files may not exist.
why the rest of the file is loaded but all the obj not show at all?


There is not enough information here for us to help you — could you post your code, or ideally a demo showing the problem? You can use tools like http://neocities.org/, http://surge.sh/, or just upload .ZIP containing your project.

the file upload says: Sorry, the file you are trying to upload is not authorized (authorized extensions: jpg, jpeg, png, gif).

copy peace of code and paste here

<!DOCTYPE html>
<html lang="en">


		<script src="js/three.js"></script>
		<script src="js/TrackballControls.js"></script>
		<script src="js/Detector.js"></script>
		<script src="js/stats.min.js"></script>

		<script src="js/MTLLoader.js"></script>
		<script src="js/LoaderSupport.js"></script>
		<script src="js/OBJLoader2.js"></script>
		<script src="js/OBJLoader.js"></script>


			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
			var container, stats;
			var camera, scene, renderer, axesHelper;
			var geometry, objects;
			var controls;
			var lod, group;
			var objPath = "../models/model_path/";
			var total_level = 7;
			var start_level = 7;
			var end_level = 7;
			var distance = [500, 400, 350, 300, 250, 200, 170, 150, 300];

			function init() {
				container = document.createElement( 'div' );
				document.body.appendChild( container );
				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
				camera.position.z = 400;

				controls = new THREE.TrackballControls( camera );

				scene = new THREE.Scene();

				light = new THREE.PointLight();
				light.position.set( 200, 100, 150 );
				scene.add( light );

				lod = new THREE.LOD();
				lod.position.set( 0, 0, 0 );
				lod.matrixAutoUpdate = false;
				scene.add( lod );

				group = new THREE.Group();

				renderer = new THREE.WebGLRenderer();
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );
				window.addEventListener( 'resize', onWindowResize, false );
			function onWindowResize() {
				camera.aspect = window.innerWidth / window.innerHeight;
				renderer.setSize( window.innerWidth, window.innerHeight );
			function animate() {

				requestAnimationFrame( animate );
			function render() {
				scene.traverse( function ( object ) {
					if ( object instanceof THREE.LOD ) {
						object.update( camera );
				} );
				renderer.render( scene, camera );

			var is_level_finished = false;
			// add target level of lod
			function initLod(target_level){
				var sideW = Math.pow(2,target_level);
				var sideTotal = Math.pow(2,total_level);
				var m, n;

					for(n=1; n<(sideW+1);n++){
						var step = Math.pow(2,(total_level-target_level));
						var x = sideTotal - m*step;
						var y = sideTotal - n*step;
						if(x==0 && y==0){
							is_level_finished = true;
						// load obj
						var filename = 'tile_'+target_level+'_'+x+'_'+y+'_tex';
						addLoadModel(target_level, filename, is_level_finished);

			// add obj mesh to group
			function addLoadModel(level, filename, is_finished){
				var mtlLoader = new THREE.MTLLoader();
				mtlLoader.load( filename+'.mtl', function( materials ) {


					var objLoader = new THREE.OBJLoader();
					objLoader.setMaterials( materials );
					objLoader.load( filename+'.obj', function (object){
						var mesh = object.children[0];
						addObjtoGroup(level,mesh, is_finished);
				}, onProgress, onError);
			// add group mesh to lod
			function addObjtoGroup(level,mesh, is_finished){
				group.add( mesh );
				var levelLength = Math.pow(4,level);
					var dist = distance[level];
					group.matrixAutoUpdate = false;
					lod.addLevel( group, dist );
					if(level < end_level){
						group = new THREE.Group();
					is_level_finished = false;

			function onProgress(){


			function onError(){
				// console.log(" ??? ");

EDIT: improved formatting and removed unnecessary <head> and <style> detail. @looeee

some of the files is not exist, and some of them are loaded, but nothing displayed in page.
is there any way i can handle before i load the mtl or obj file in three.js?
or is there any better way for me to do lod?

:frowning: is there any solution ?


You overestimate people here. We, just looking at your code, can’t compile it in our heads and say what’s wrong there. Especially, when we don’t have .obj and .mtl files, which organized with the same file structure like you have it.
I totally agree with @donmccurdy here. Finally, you can use any file-sharing service to upload you .zip with the project, if it’s not a great secret.

ok,i will later upload the whole project :slight_smile:
and btw, what i want to do is load large objs like altizure do, use lod tech.
if anyone could tell me what to do, i will be very very appreciate

I’ve opened your page and got no error messages or warnings in browser console.

www.altizure.cn / www.altizure.com
this is the official website of the company. they are doing well in 3d model render.
that’s what i want :):blush:

First of, the error message net::ERR_INSUFFICIENT_RESOURCES is something that might happen in Google Chrome when it tries to load a lot of resources (images or other assets) in a very short period of time.

There is an ongoing issue regarding this matter.

As for your code…

The 404 (Not found) issues you’re having with .mtl files, this isn’t something we can look into without having access to your project. But my gut feeling tells me it’s either a bad model export or the “base path” of your MTLLoader isn’t set-up correctly.

That said, be aware that the path "../models/model_path/" that you define as objPath isn’t relative to your script, but to the page that is executing the script, say index.html.

For example, if your webpage is located at “http://your-3d-project.com/something/public/index.html”, then your .mtl files should be accessible from “http://your-3d-project.com/something/models/model_path/”. (now that I type this out, I think you copy-pasted “model_path” from somewhere that was there as a placeholder)

Also, you shouldn’t constantly re-instantiate a loader like you’re doing in addLoadModel. Just declare it once, and reuse it everywhere else afterward.

yes~ my problem is i know some of the objs in the loop is missing, but i dont know which is missing.
i want to load them all and avoid those error.
btw, what i really did is separate a large model to amounts of objs in quadtree. i want to load them all with lod.

You’re adding meshes to group, but you are missing scene.add( group ).

i did:
lod.addLevel( group, dist );