|
75 | 75 | live2d.glInit() |
76 | 76 | # CreateRenderer should be called after OpenGL context is created and glInit is called |
77 | 77 | # maskBufferCount = 2 |
| 78 | +# more info about maskBufferCount: https://docs.live2d.com/zh-CHS/cubism-sdk-manual/ow-sdk-mask-premake/ |
| 79 | +# typically maskBufferCount = 2 is enough for most cases |
78 | 80 | model.CreateRenderer(2) |
79 | 81 |
|
80 | 82 | lastUpdateTime = time.time() |
|
158 | 160 | ct = time.time() |
159 | 161 | # delta seconds |
160 | 162 | deltaSecs = ct - lastUpdateTime |
161 | | - deltaSecs = max(0.001, deltaSecs) |
| 163 | + deltaSecs = max(0.0001, deltaSecs) |
162 | 164 | lastUpdateTime = ct |
163 | 165 |
|
164 | | - # the following lines are equal to LAppModel.Update() |
| 166 | + # the following section is equal to LAppModel.Update() |
| 167 | + |
| 168 | + # === Section Start Update() === |
165 | 169 | # load cached parameters from last frame |
166 | 170 | motionUpdated = False |
167 | | - model.LoadParameters() |
| 171 | + model.LoadParameters() # initialize params using cached values |
| 172 | + |
168 | 173 | if not model.IsMotionFinished(): |
169 | 174 | motionUpdated = model.UpdateMotion(deltaSecs) |
170 | 175 |
|
171 | 176 | # if SetParameterValue is called here, the parameter will be saved to the cache |
172 | | - model.SaveParameters() |
| 177 | + # model.SetParameterValue(StandardParams.ParamAngleX, params.AngleX, 1) |
| 178 | + |
| 179 | + model.SaveParameters() # save params to cache for next frame |
173 | 180 |
|
174 | 181 | if not motionUpdated: |
175 | | - model.UpdateBlink(deltaSecs) # auto blink |
| 182 | + # auto blink |
| 183 | + # update eye blink params if they are defined in the model3.json |
| 184 | + model.UpdateBlink(deltaSecs) |
176 | 185 |
|
177 | 186 | model.UpdateExpression(deltaSecs) |
178 | 187 |
|
179 | 188 | model.UpdateDrag(deltaSecs) |
180 | 189 |
|
181 | | - model.UpdateBreath(deltaSecs) # auto breath |
| 190 | + # auto breath |
| 191 | + # update breath params such as ParamBodyAngleX, ParamAngleX... |
| 192 | + model.UpdateBreath(deltaSecs) |
182 | 193 |
|
183 | | - # create physics effects according to the parameters set |
| 194 | + # create physics effects according to current and previous param values |
| 195 | + # some params can be overridden by physics effects |
184 | 196 | model.UpdatePhysics(deltaSecs) |
185 | 197 |
|
186 | 198 | model.UpdatePose(deltaSecs) |
| 199 | + # === Section End Update() === |
187 | 200 |
|
| 201 | + # Draw(): |
| 202 | + # 1. update meshes according to the parameters |
| 203 | + # 2. draw meshes using opengl |
188 | 204 | model.Draw() |
189 | 205 |
|
190 | 206 | pygame.display.flip() |
|
0 commit comments