garrysmod-issues icon indicating copy to clipboard operation
garrysmod-issues copied to clipboard

Model rendering issues when using NPC models

Open impulsh opened this issue 7 years ago • 32 comments

When using NPC models as player models and overriding some animation code to translate activities properly, they will sometimes cause various issues when the model is rendered.

The most reliable way that I've found to make it happen is to use a map that has some PVS optimization (my test map is https://steamcommunity.com/sharedfiles/filedetails/?id=1532126505) and have two players be a fair distance apart and in different visleaves. After waiting a couple of minutes, bring the players back together and there's about a 1 in 3 chance that they will have some sort of bone issue. It's more likely to happen for yourself if you are tabbed out of the game.

Forcing a full update for your client will resolve this issue temporarily, and many players have resorted to having to use record 1; stop in console to do so.

There are a couple different kinds of bugs that will happen, including incorrect bone rotation: https://i.imgur.com/dRiHaXs.jpg

Models not rendering at all: https://streamable.com/c2y7z

And models twitching left and right rapidly, which I couldn't get a video of at the moment.

I've isolated this issue with a test gamemode that includes a stripped down version of the animation code that we use. No other addons/lua files have been ran except for the gamemode code and base GMod stuff. You can check out the gamemode here https://gist.github.com/impulsh/b6de45e03ecf5b2c5d722a1bea07ee0e

impulsh avatar Oct 21 '18 00:10 impulsh

The issues that are happening seems to be similar to #3010. Using the fix from https://github.com/ValveSoftware/source-sdk-2013/issues/404#issuecomment-405042224 might solve the problem

impulsh avatar Oct 24 '18 07:10 impulsh

Bone positions become completely invalid which is the point at which the player becomes completely invisible.

] lua_run_cl print(LocalPlayer():GetEyeTraceNoCursor().Entity:GetBonePosition(1))
-nan(ind) -nan(ind) -nan(ind)    nan nan 0.000

alexgrist avatar Nov 18 '18 20:11 alexgrist

@willox @robotboy655

its-johnny avatar Nov 18 '18 23:11 its-johnny

This also seems to happen for regular player models, although not nearly as frequent as NPC models it seems

impulsh avatar Nov 20 '18 22:11 impulsh

Merged the potential fix from https://github.com/ValveSoftware/source-sdk-2013/issues/404#issuecomment-405042224 Let me know if that fixes it.

robotboy655 avatar Nov 21 '18 17:11 robotboy655

When would this be pushed to the dev branch?

impulsh avatar Nov 21 '18 22:11 impulsh

All changes are pushed to Dev branch within minutes of them being committed automatically.

robotboy655 avatar Nov 21 '18 22:11 robotboy655

The patch has fixed it partially, players no longer go invisible at all and the spine twisting/twitching seems much less frequent.

alexgrist avatar Nov 22 '18 22:11 alexgrist

Not sure if this was reverted in the latest patch but it seems to have started occurring frequently since.

alexgrist avatar Jan 04 '19 20:01 alexgrist

It wasn't.

robotboy655 avatar Jan 04 '19 21:01 robotboy655

I'm seeing this a lot now on citizen based NPC models, the spine is turned roughly 90 degrees to the right if I'm not mistaken. Happening frequently to those with higher FPS.

MuckerMayhem avatar Feb 10 '19 00:02 MuckerMayhem

Been starting to see this more and more often now that I'm entering gamemodes with higher FPS, honestly a weird occurrence and I've seen this occur on both Citizen and Combine based models

WolffeUS avatar Feb 10 '19 05:02 WolffeUS

I could only speculate that it's becoming more of an issue with the x64 branch if that's where you're testing it.

And yes, the higher the FPS the higher the chance of it happening (max_fps 120 on the client should prevent it from happening as a workaround), but really, it wasn't a problem anymore with the Lerp_Hermite specialisation, so I'm at a loss as to where else it could come from, someone would need to do some deep digging if it still has to do with the pose params going out of bounds.

neico avatar Feb 10 '19 11:02 neico

The only workaround I've found is starting to record a demo with 'record demo' in console, then following it up with 'stop'.

Kouch1 avatar Feb 10 '19 17:02 Kouch1

Yeah, that forces a full client update which would usually be done with cl_fullupdate but that command requires cheats.

alexgrist avatar Feb 10 '19 17:02 alexgrist

@robotboy655 Could this get reopened? This issue seems to still be persisting even through the lerp fix

impulsh avatar Feb 12 '19 07:02 impulsh

We've found a pretty reproducible test case for triggering the issue. It isn't as extreme as we've seen in the wild, but it's as good as it's going to get in terms of reliably reproducing the issue.

We simply switched between the male_01 and police models a couple times and it would happen almost every time as captured in this video: https://streamable.com/mebf8. It shows the model being switched 6 times and with the final switch back to the male_01 model, you can see the spine being distorted. Shortly after, cl_fullupdate was used to reset the entity and fix the issue.

The issue also shows up in demos, so I've uploaded one at https://www.dropbox.com/s/mw4a27ucacgcieo/animtest.dem if it's at all useful.

The test code that was used is below. The gamemode used is the one linked in the OP (https://gist.github.com/impulsh/b6de45e03ecf5b2c5d722a1bea07ee0e).

concommand.Add("animmodel", function(client)
	for i = 1, 3 do
		timer.Simple(i * 0.1, function()
			local newModel = client:GetModel() == "models/humans/group01/male_01.mdl" and "models/police.mdl" or "models/humans/group01/male_01.mdl"
			client:SetModel(newModel)
		end)
	end
end)

impulsh avatar Feb 13 '19 07:02 impulsh

It appears as if changing the model results in the pose parameters being copied over, but the models have different pose parameters (or pose parameters are stored in a different order.)

I can't say for sure it is related to your first post, but I can try to fix it. I would assume this only causes any issues when the players' model is changed.

sohpeach avatar Feb 25 '19 14:02 sohpeach

I pushed a fix for that to the dev branch. I'm still not sure if it'll fix the actual issue.

sohpeach avatar Feb 25 '19 18:02 sohpeach

It appears as if changing the model results in the pose parameters being copied over, but the models have different pose parameters (or pose parameters are stored in a different order.)

I can't say for sure it is related to your first post, but I can try to fix it. I would assume this only causes any issues when the players' model is changed.

I'll give it a test. This happens on it's own over time (5-10 minutes) without any model changes but changing the model a couple times is the most reproducable trigger of the issue.

alexgrist avatar Feb 25 '19 18:02 alexgrist

I pushed a fix for that to the dev branch. I'm still not sure if it'll fix the actual issue.

It's happening less frequently now, however, it is still noticeable in a couple of players over time 10minutes & People still continue to go invisible which in combat screws over the person they're fighting against. m8cfvqe

Jaydawg8888 avatar Feb 25 '19 19:02 Jaydawg8888

I can confirm that it is still reproduced when I change the player model to the NPCs model and back. Some pose parameters goes up to 300k or even inf/nan by engine.

ClearPoseParameters right after the model change does not help. but I can just set player:SetPoseParameter("body_yaw", 0) for example in UpdateAnimation and forget.

Or maybe the calculation code of "body_yaw" is completely broken.

TIMONz1535 avatar Feb 03 '24 12:02 TIMONz1535

I have made some changes that may or may not help with this.

I could never reproduce this the way described above, but I did cause similar issues by manually setting cycle to infinity in the engine.

robotboy655 avatar Feb 27 '24 19:02 robotboy655

I am considering this solved for now, unless someone can disprove it.

robotboy655 avatar Mar 21 '24 19:03 robotboy655