--- /usr/share/blender/scripts/blender/3ds_export.py	2008-05-19 08:37:25.000000000 -0600
+++ 3ds_export.py	2008-09-02 09:10:30.000000000 -0600
@@ -505,7 +505,7 @@
 		self.offset= [0, 0, 0] # offset indicies
 
 
-def extract_triangles(mesh):
+def extract_triangles(mesh, face_offset, face_limit):
 	'''Extract triangles from a mesh.
 	
 	If the mesh contains quads, they will be split into triangles.'''
@@ -516,30 +516,31 @@
 		face_uv = None
 	
 	img = None
-	for face in mesh.faces:
-		f_v = face.v
-		
-		if do_uv:
-			f_uv = face.uv
-			img = face.image
-			if img: img = img.name
-		
-		if len(f_v)==3:
-			new_tri = tri_wrapper((f_v[0].index, f_v[1].index, f_v[2].index), face.mat, img)
-			if (do_uv): new_tri.faceuvs= uv_key(f_uv[0]), uv_key(f_uv[1]), uv_key(f_uv[2])
-			tri_list.append(new_tri)
-		
-		else: #it's a quad
-			new_tri = tri_wrapper((f_v[0].index, f_v[1].index, f_v[2].index), face.mat, img)
-			new_tri_2 = tri_wrapper((f_v[0].index, f_v[2].index, f_v[3].index), face.mat, img)
-			
-			if (do_uv):
-				new_tri.faceuvs= uv_key(f_uv[0]), uv_key(f_uv[1]), uv_key(f_uv[2])
-				new_tri_2.faceuvs= uv_key(f_uv[0]), uv_key(f_uv[2]), uv_key(f_uv[3])
+	for i, face in enumerate(mesh.faces):
+		if i >= face_offset and i < face_limit:
+			f_v = face.v
+		
+			if do_uv:
+				f_uv = face.uv
+				img = face.image
+				if img: img = img.name
+		
+			if len(f_v)==3:
+				new_tri = tri_wrapper((f_v[0].index, f_v[1].index, f_v[2].index), face.mat, img)
+				if (do_uv): new_tri.faceuvs= uv_key(f_uv[0]), uv_key(f_uv[1]), uv_key(f_uv[2])
+				tri_list.append(new_tri)
+		
+			else: #it's a quad
+				new_tri = tri_wrapper((f_v[0].index, f_v[1].index, f_v[2].index), face.mat, img)
+				new_tri_2 = tri_wrapper((f_v[0].index, f_v[2].index, f_v[3].index), face.mat, img)
+			
+				if (do_uv):
+					new_tri.faceuvs= uv_key(f_uv[0]), uv_key(f_uv[1]), uv_key(f_uv[2])
+					new_tri_2.faceuvs= uv_key(f_uv[0]), uv_key(f_uv[2]), uv_key(f_uv[3])
+			
+				tri_list.append( new_tri )
+				tri_list.append( new_tri_2 )
 			
-			tri_list.append( new_tri )
-			tri_list.append( new_tri_2 )
-		
 	return tri_list
 	
 	
@@ -694,12 +695,12 @@
 	uv_chunk.add_variable("uv coords", uv_array)
 	return uv_chunk
 
-def make_mesh_chunk(mesh, materialDict):
+def make_mesh_chunk(mesh, materialDict, face_offset, face_limit):
 	'''Make a chunk out of a Blender mesh.'''
 	
 	# Extract the triangles from the mesh:
-	tri_list = extract_triangles(mesh)
-	
+	tri_list = extract_triangles(mesh, face_offset, face_limit)
+
 	if mesh.faceUV:
 		# Remove the face UVs and convert it to vertex UV:
 		vert_array, uv_array, tri_list = remove_face_uv(mesh.verts, tri_list)
@@ -954,22 +955,41 @@
 	# Create object chunks for all meshes:
 	i = 0
 	for ob, blender_mesh in mesh_objects:
-		# create a new object chunk
-		object_chunk = _3ds_chunk(OBJECT)
-		
-		# set the object name
-		object_chunk.add_variable("name", _3ds_string(sane_name(ob.name)))
-		
-		# make a mesh chunk out of the mesh:
-		object_chunk.add_subchunk(make_mesh_chunk(blender_mesh, materialDict))
-		object_info.add_subchunk(object_chunk)
+
+		if len(blender_mesh.verts) > 65535:
+			print 'WARNING::: too many vertices per named mesh, will produce *corrupted export*'
+
+		if len(blender_mesh.faces) > 65535:
+			print 'WARNING:: too many faces per named mesh, will try to split to multiple named objects'
+
+		faces_total = len(blender_mesh.faces)
+		face_offset = int(0)
+
+		while face_offset < faces_total:
+
+			face_do = int(faces_total - face_offset)
+
+			if face_do > 40000:
+				face_do = int(40000)
+
+			# create a new object chunk
+			object_chunk = _3ds_chunk(OBJECT)
+
+			# set the object name
+			object_chunk.add_variable("name", _3ds_string(sane_name(ob.name)))
+
+			# make a mesh chunk out of the mesh:
+			object_chunk.add_subchunk(make_mesh_chunk(blender_mesh, materialDict, face_offset, face_offset + face_do))
+			object_info.add_subchunk(object_chunk)
 		
-		''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX
-		# make a kf object node for the object:
-		kfdata.add_subchunk(make_kf_obj_node(ob, name_to_id))
-		'''
-		blender_mesh.verts = None
-		i+=i
+			''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX
+			# make a kf object node for the object:
+			kfdata.add_subchunk(make_kf_obj_node(ob, name_to_id))
+			'''
+			#blender_mesh.verts = None
+			i+=i
+
+			face_offset += face_do
 
 	# Create chunks for all empties:
 	''' # COMMENTED OUT FOR 2.42 RELEASE!! CRASHES 3DS MAX
