Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tags in this Discussion

Physics simulation result is delayed?
  • Hi:

    I am using APEX sdk and modifying 1 of the sample (SimpleClothing) to do some work.
    I bind a clothes(apx file) to an object(ezm file), and I move the object in my graphic world.

    The clothes is moving with the object to the same position and has physics simulation effect, but the problem is, the clothes is delayed.

    The clothes is like 1 or 2 seconds paused, and it starts to move; by this 1 second, the object has already moved to the right position and waiting for the clothes.

    Is this because the simulation needs too much time to finish the calculation so that it is delayed?
    And why the dtime is set to 1/60 for the m_apexScene->simulate(dtime) call?

    Thanks!
  • 5 Comments sorted by
  • I am not sure I fully understand what's going on when you say the cloth is delayed.
    Are you using the apx/ezm files we distribute with our samples or did you generate your own ones?

    If you load a clothing mesh and simulation doesn't start immediately there is two possible reasons.
    1) The LOD system thinks the benefit of the cloth is too small to be simulated (either because the camera is very far, or the LOD numbers are not well set up)
    2) The clothing asset doesn't have properly cooked data inside. In this case the clothing actor will cook the cloth data at runtime before it can start simulation. This usually only takes a few ms (and runs in a separate thread) so the cloth just won't simulate the first few frames.
    However, in both situations the cloth should move with the character, it just won't simulate. So once simulation starts it should already be at the right place.

    dtime is set to 1/60 because we set vsync to true. Also it's very important for cloth simulation to have a constant (or near constant) dtime.

    --Philipp
  • Hi Philipp:

    Nice to see you again! :)

    I'm using my own apx/ezm files, but the code base is your sample.
    I am not using LOD feature; my apx file has only 1 level of detail.
    The camera is close to my clothes, and I see the clothes are simulating when I press "V" to show physical meshes.
    The clothes are always simulating, but it just lags in moving.

    I will try my best to explain the situation:
    My cloth(my own apx) is attached to a hanger(my own ezm)(as hanger's mFollower), and when I move the hanger by setting m_globalpose in its tick(), it moves to my desired place.
    However the clothes stops where it is until 0.5 second (or so) later, then it simulates and moves to the same place as hanger.

    I press "R" to show debug info, and I see PhysxSimulationTime is around 10~13 ms, I think it is fairly high becoz sample's time is only 0.1~0.4 ms. I think the reason is I am using high vertices apx files (total vertices in simulation is around 60K). But I'm not sure if this is the cause of lag. I also notice that UserDelayedFetchTime is 0.00, but it is some number in sample. Is there any way to set this value?

    Marson
  • Hi

    From what you write it doesn't sound like you're doing anything wrong. the long simulation time is expected when simulating 60k vertices, normal clothing assets are around 300-1500 vertices.

    If you don't mind you could send me (PM) the apx/ezm and the modified source code so that I can run it on my machine. Then I can probably tell you what is going on.

    --Philipp
  • My boss said I can not distribute the codes, but I think the files are ok, I will PM you.
    (Anyway the code project is huge and needs a lot of asset files)

    I will provide more info though:
    I did some test and made the simulation time down to 0.5 ms(by reducing vertices and amount of clothes in the scene), but the clothes are still falling behind.

    My frame rate is about 5~10. When I disable some functions in my project, the FPS goes to 15, and the clothes are not lagging too much like before, but this is just an "acceleration", the situation is the same.
    This makes me wonder if the lag is always there? but disappears only because of high FPS? (so that the lag time is too short to perceive).

    One other difference from sample is that I dont use animation for character. I directly set the globalPose for it per frame.
    I try the same method with a clean sample code, by setting global pose of character in ontickPreRender(). I add actors to reduce FPS to 9, and the situation is very likely, but the lag is slight.

    So, is it wrong to manually set mGlobalPose of SampleAnimatedMeshActor? Because I dont see any manual set in the sample code.
  • I was hoping you could send me the modified SimpleClothing code and your assets, not your entire project :)

    But in general, if the size of the lag depends on framerate I start to wonder whether the global pose you set maybe is a frame (or more) old. Then the difference would be bigger the lower the framerate is? You could also turn on debug rendering for skinned positions again, those should show whether the lag is already from old matrices or whether it gets introduced later during simulation

    --Philipp