Proper way to use ModelCache?

Anything libgdx related goes here!

Proper way to use ModelCache?

Postby HydroZeppelin » Tue Feb 06, 2018 10:53 am

Hey guys.

So I'm trying to make sense of the ModelCache class by using it to batch together all of my world's static objects. I've been testing it out with basic boxes and so far it's been giving me strange results. It batches everything together fine, but the rendering looks seriously messed up. This is, very roughly, the code I use:

Code: Select all
void draw(ModelBatch batch)
{
    this.modelCache.begin(this.playerCamera);
    this.modelCache.add(box1);
    this.modelCache.add(box2);
    this.modelCache.add(box3);
    this.modelCache.add(box4);
    this.modelCache.end();

    batch.begin(this.playerCamera);
    batch.draw(this.modelCache, this.environment);
    batch.end();
}


If I use the above code to render the boxes, the culling seems to be way off. If the player looks at a row of boxes, one box placed behind the other, all of the boxes are rendered when only the one closest to the player should be visible. If I render each of the boxes individually, without first placing them in the modelCache, then the scene is rendered perfectly.

Is there something I'm fundamentally doing wrong in my implementation? Am I misunderstanding the purpose of the ModelCache class (i.e. is it not to be used to batch static models during rendering)? I've done extensive googling on the class, but can't seem to find many people talking about the ModelCache class at all. It seems to be a relatively recent addition to libgdx.

I'm kind of worried I'm overlooking something very obvious which nobody else has been stupid enough to also overlook yet, though I certainly wouldn't complain if there's a simple answer to my problem! Any advice would be appreciated :)
HydroZeppelin
 
Posts: 7
Joined: Tue Feb 06, 2018 10:50 am

Re: Proper way to use ModelCache?

Postby xoppa » Tue Feb 06, 2018 6:14 pm

If the player looks at a row of boxes, one box placed behind the other, all of the boxes are rendered when only the one closest to the player should be visible

Both ModelCache and ModelBatch don't have any notion of whether things "should be visible". Perhaps show your SSCCE to show exactly what you mean.
xoppa
 
Posts: 689
Joined: Thu Aug 23, 2012 11:27 pm

Re: Proper way to use ModelCache?

Postby HydroZeppelin » Wed Feb 07, 2018 9:01 am

Perhaps show your SSCCE to show exactly what you mean.

I'd be glad to, though I'm in work at the moment so I may be a while.

I seem to have gotten the ModelCache rendering objects in the correct order by passing the camera's RenderableSorter through the ModelCache's constructor during its creation. Seems a pretty obvious thing to do now that I've gotten it working. I haven't seen any of the ModelCache code example use that particular constructor, which is what threw me off as I assumed that it was constructor that's rarely used/not needed for it to work correctly.

Now that it's rendering correctly though, performance seems to be worse when rendering the ModelCache as a whole rather than when rendering individual boxes one at a time, which is slightly concerning.
HydroZeppelin
 
Posts: 7
Joined: Tue Feb 06, 2018 10:50 am

Re: Proper way to use ModelCache?

Postby xoppa » Fri Feb 09, 2018 5:43 pm

Yeah using the RenderableSorter of ModelBatch with ModelCache wont gain you anything. You might as well not use ModelCache at all in that case.
xoppa
 
Posts: 689
Joined: Thu Aug 23, 2012 11:27 pm

Re: Proper way to use ModelCache?

Postby HydroZeppelin » Wed Feb 14, 2018 9:05 am

Is there something I'm fundamentally misunderstanding about the ModelCache in that case? I'm basically trying to create a POV dungeon crawler where the map is constructed from boxes (I'm using them as 3d "tiles") and other simple geometry. I thought I could render all of the models which make up the map (ceilings/floors/walls) together by placing them in the ModelCache and just rendering that. Is this an incorrect use of ModelCache?

I'll post a couple of images of what I expect it to look like and what actually happens when I use a ModelCache when I get home from work.
HydroZeppelin
 
Posts: 7
Joined: Tue Feb 06, 2018 10:50 am


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest