🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

ASSIMP takes forever to load OBJ models

Started by
9 comments, last by yaboiryan 3 years, 11 months ago

Hello,

I am making a game with OpenGL and Assimp and I was trying to do simple animations. Instead of implementing a new model format, I decided to just create a model loader that is able to load in .obj animations (the ones that exports each individual model in each individual frame).

I had used this technique in the past with an OBJ loader that I had personally created and it worked perfectly!

When I use Assimp, on the other hand, I get incredibly slow performance when I do this, making the technique pointless because it slows the game down so much.

Here is the code I am using for the .OBJ file animator:

		int i = 250;

		std::string filename = "anim/cloth";
		int num = 250;

		char tmp[200];
		while( !glfwWindowShouldClose( window ) )
		{
		...		
		...
		...		
				if (i >= 250)
				{
					i = 0;
				}
				i += 1.0f;
					

					if (i < 10)
						sprintf(tmp, "_00000%d", i);
					else if (i < 100)
						sprintf(tmp, "_0000%d", i);
					else if (i < 1000)
						sprintf(tmp, "_000%d", i);
					else if (i < 10000)
						sprintf(tmp, "_00%d", i);
					else if (i < 100000)
						sprintf(tmp, "_0%d", i);
					else if (i < 1000000)
						sprintf(tmp, "_%d", i);
					std::string tmp2(filename + tmp);
					tmp2 += ".obj";
					std::cout << tmp2 << std::endl;
					
					Model modelCloth(tmp2.c_str());

				
				
				modelCloth.DrawModel(shader);

THIS CODE IS IN MY WHILE LOOP

I am quite sure that code slows down because of this line:

	Model modelCloth(tmp2.c_str());

but I cannot figure out any better way to do it because all the constructor does is just load in the model that is called in from the string…

Does anyone have any clues to what this could be? I have tried moving it around random places, and I just cannot figure out how to increase the model object loading speed.

Advertisement

yaboiryan said:
I am quite sure that code slows down because of this line:

Use a profiler to actually be sure, and make sure using release build settings.

You haven't really provided anything to use a a point of reference here on “slow” and “fast”. How big is the model? Are you loading a model every frame? Try to load all models just once in advance.

If you are going to be dynamically loading models during the game, you need to multi-thread some of it to not block the main game threads. And probably obj is really not the best format for that, use a binary format that requires less parsing effort.

What's the reason you're loading the model every frame? Is this a test harness?

Yep, the problem is 100% that you're loading the model over on every frame. You need to pull the load out of the loop, or only do it once somewhere else.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

@Promit But I need to do that every frame… that is how the animation works.

@undefined Im doing it so I can get animations without having to worry about .dae files.

yaboiryan said:

@Promit But I need to do that every frame… that is how the animation works.

You're saying you can't load each frame up front before the loop, into a collection of frames representing the animation, before you start playing the animation? Why? Does the whole animation not fit into memory? Are you trying to implement a streaming system?

It isn't really usual to have every separate frame be its own model, if only for the simple reason that this is a LOT of duplicated data. Skeletal animation cuts down on the amount of data needed considerably and using keyframes/tweening helps even more.

If you REALLY need to be streaming individual frames as models from disk, then I highly suggest bundling your models into an optimized format that can be loaded into memory quickly, without having to invoke Assimp in the first place (in the game, anyway - you'd need separate tool to convert it from a bunch of .objs to whatever your custom format is). That is the typical flow for custom game engines. Ideally they would all be bundled into ONE file to cut down on I/O usage. Going to disk for data is slooooow.

In fact, I recommend doing that even if you're using skeletal animation and keyframing.

@yaboiryan Ok this is like, the worst idea. But if you're hellbent on doing it this way, make an array (or std::vector) and load all of the models in there ahead of time. Then pull them from that array during rendering instead.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

@Promit hahaha Thanks man that worked! You are the best!

@oberon_command @sync views @promit

Thank all of you! I have spent so long trying to figure out this issue! You saved me several more hours of confusion!

This topic is closed to new replies.

Advertisement