Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(w3ddevice): draw a model its animation carries out of its bind pose

Olcay Seygan4024681f105f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bcd936c63..8e14c4e4b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1008,6 +1008,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- Confirming the "recorded by an older version" warning plays the replay you picked. The menu behind the warning stays live, so deleting a replay while it was up rebuilt the list, and the row number the warning had been opened on now belonged to something else - which is what you got, with nothing to tell you.
- The building outline and the target circle stay where they are when the cursor crosses the skyline. There is no ground above the horizon, and the game took the miss for an answer: the corner of the map. Every time the mouse went over the horizon the ghost you were placing shot across the world and back.
- The radar stops reading a hero who has just died. It kept the unit's own position rather than a copy of it, and only rebuilt that list every sixth frame, so the five frames after a hero fell were spent looking at a unit that was no longer there.
+- The plane at the end of the first GLA mission stays in the picture until it flies over the camera. Its whole takeoff is an animation of the model, so the game thought it was still standing on the runway, and once the camera moved on from that spot it stopped drawing the plane two seconds before the screen went black, mid-climb. Any model whose animation carries it away from where it stands is now drawn wherever its parts are.
- A mission that asks to see more of the ground gets more of it. The script action for widening the drawn terrain was written when the game drew a square of map around the camera and pushed that square out; this one already draws the whole map, so the same arithmetic handed back a patch a few hundred feet across and the ground ended in mid air - in exactly the cutscenes that asked to see further.
- Tank tracks no longer crash the game. The renderer has to borrow the buffer it writes them into, and when that request failed, which is what a graphics device pulled out from under the game does, the tracks were written to address zero anyway. Two more of the same shape went with it: the screenshot path and the texture size lookup both used a pointer that the failing call had never filled in. Three of those texture lookups also leaked the surface they asked about, once per procedural texture, for the life of the process.
- Double-clicking a menu button opens the screen once. The button stays live while the old screen animates out, so the second click started the same transition again and the screen opened twice, one copy left drawn over whatever came next and doing nothing sensible when clicked.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/DrawableInfo.h b/GeneralsMD/Code/GameEngine/Include/GameClient/DrawableInfo.h
index 96570836b..5e4938c75 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/DrawableInfo.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/DrawableInfo.h
@@ -48,12 +48,13 @@ struct DrawableInfo
ERF_DELAYED_RENDER = ERF_IS_TRANSLUCENT|ERF_POTENTIAL_OCCLUDEE,
};
- DrawableInfo(void) : m_shroudStatusObjectID(INVALID_ID), m_drawable(NULL), m_ghostObject(NULL), m_flags(ERF_IS_NORMAL) {}
+ DrawableInfo(void) : m_shroudStatusObjectID(INVALID_ID), m_drawable(NULL), m_ghostObject(NULL), m_flags(ERF_IS_NORMAL), m_animLeavesBindPose(FALSE) {}
ObjectID m_shroudStatusObjectID; ///<since we sometimes have drawables without objects, this points to a parent object from which we pull shroud status.
Drawable *m_drawable; ///<pointer back to drawable containing this DrawableInfo
GhostObject *m_ghostObject; ///<pointer to ghostObject for this drawable used for fogged versions.
Int m_flags; ///<extra render settings flags that are tied to render objects with drawables.
+ Bool m_animLeavesBindPose; ///<the model's animation carries it out of its bind-pose bounds, so culling tests the posed parts too
};
#endif // _DRAWABLEINFO_H_
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
index 4c3845086..5911ee704 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
@@ -2473,6 +2473,30 @@ Real W3DModelDraw::getCurrentAnimFraction() const
}
}
+//-------------------------------------------------------------------------------------------------
+/** Whether an animation moves a bone further than the model's bind pose reaches. W3D culls a model
+ * by its bind pose, and the cinematic transports fly their whole route in their bones: the plane
+ * GLA01 ends on (CINE_CPlane) climbs 1400 units away from the runway spot it stands on, and dropped
+ * out of the picture mid-air the moment the camera stopped looking at that spot. */
+//-------------------------------------------------------------------------------------------------
+static Bool animLeavesBindPose(HAnimClass *anim, RenderObjClass *robj)
+{
+ const Real reach = robj->Get_Bounding_Sphere().Radius;
+ const Int lastFrame = anim->Get_Num_Frames() - 1;
+ for (Int pivot = 1; pivot < anim->Get_Num_Pivots(); ++pivot)
+ {
+ if (!anim->Is_Node_Motion_Present(pivot))
+ continue;
+ Vector3 first, middle, last;
+ anim->Get_Translation(first, pivot, 0.0f);
+ anim->Get_Translation(middle, pivot, lastFrame * 0.5f);
+ anim->Get_Translation(last, pivot, (Real)lastFrame);
+ if ((middle - first).Length() > reach || (last - first).Length() > reach)
+ return TRUE;
+ }
+ return FALSE;
+}
+
//-------------------------------------------------------------------------------------------------
void W3DModelDraw::adjustAnimation(const ModelConditionInfo* prevState, Real prevAnimFraction)
{
@@ -2538,6 +2562,7 @@ void W3DModelDraw::adjustAnimation(const ModelConditionInfo* prevState, Real pre
}
m_renderObject->Set_Animation(animHandle, startFrame, m_curState->m_mode);
+ getDrawable()->getDrawableInfo()->m_animLeavesBindPose = animLeavesBindPose(animHandle, m_renderObject);
REF_PTR_RELEASE(animHandle);
animHandle = NULL;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
index 7938afcde..db6a75e01 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DScene.cpp
@@ -427,6 +427,33 @@ Bool RTS3DScene::castRay(RayCollisionTestClass & raytest, Bool testAll, Int coll
return hit;
}
+//=============================================================================
+// posedPartsInView
+//=============================================================================
+/** A model whose animation carries it out of its bind pose (W3DModelDraw's animLeavesBindPose) is
+ * in view when any of its parts is, as they stand now. A culled model is not drawn, and drawing
+ * is what moves its animation on, so setting its transform again (which marks the hierarchy stale)
+ * and asking for a bone poses it at the current frame first. */
+//=============================================================================
+static Bool posedPartsInView(RenderObjClass *robj, CameraClass *camera)
+{
+ const DrawableInfo *drawInfo = (const DrawableInfo *)robj->Get_User_Data();
+ if (drawInfo == NULL || !drawInfo->m_animLeavesBindPose || robj->Class_ID() != RenderObjClass::CLASSID_HLOD)
+ return FALSE;
+
+ const Matrix3D transform = robj->Get_Transform();
+ robj->Set_Transform(transform);
+ robj->Get_Bone_Transform(0);
+ Bool inView = FALSE;
+ for (Int i = 0; i < robj->Get_Num_Sub_Objects() && !inView; ++i)
+ {
+ RenderObjClass *part = robj->Get_Sub_Object(i);
+ inView = !camera->Cull_Sphere(part->Get_Bounding_Sphere());
+ part->Release_Ref();
+ }
+ return inView;
+}
+
//=============================================================================
// RTS3DScene::Visibility_Check
//=============================================================================
@@ -482,7 +509,7 @@ void RTS3DScene::Visibility_Check(CameraClass * camera)
// The same test the main pass hides a drawable by, or a unit under the fog of war,
// or a building standing in for its own ghost, shows up in the water and nowhere else.
Bool hidden = robj->Is_Hidden() || draw->isDrawableEffectivelyHidden() || draw->getFullyObscuredByShroud();
- robj->Set_Visible(!hidden && draw->getDrawsInMirror() && !camera->Cull_Sphere(robj->Get_Bounding_Sphere()));
+ robj->Set_Visible(!hidden && draw->getDrawsInMirror() && (!camera->Cull_Sphere(robj->Get_Bounding_Sphere()) || posedPartsInView(robj, camera)));
}
}
else
@@ -510,7 +537,7 @@ void RTS3DScene::Visibility_Check(CameraClass * camera)
robj->Set_Visible(false);
} else {
- bool isVisible=!camera->Cull_Sphere(robj->Get_Bounding_Sphere());
+ bool isVisible=!camera->Cull_Sphere(robj->Get_Bounding_Sphere()) || posedPartsInView(robj, camera);
if (isVisible)
{ //need to keep track of occluders and ocludees for subsequent code.