I have a custom model format that I’m trying to load. The skeleton definition specifies each bone and whether each bone has a parent and the exact world-space position where the bone is to be rendered. I attempted to populate the Urho3D Skeleton
as follows:
Urho3D::Vector<Urho3D::Bone>& bones = skeleton.GetModifiableBones();
for ( const ModelBone &mBone : modelBones )
{
const auto parentIndex = mBone.parentBoneId < 0 ? i : mBone.parentBoneId;
Urho3D::Bone &bone;
bone.name_ = Urho3D::ToString( "Bone%u", mBone.boneId );
bone.nameHash_ = bone.name_;
bone.parentIndex_ = parentIndex;
bone.initialPosition_ = Urho3D::Vector3( mBone.pivot.x, mBone.pivot.y, mBone.pivot.z );
if ( bone.parentIndex_ != i )
{
unsigned index = bone.parentIndex_;
while ( true )
{
const Urho3D::Bone &parent = bones[ index ];
bone.initialPosition_ -= parent.initialPosition_;
if ( parent.parentIndex_ == index )
break;
index = parent.parentIndex;
}
}
bone.offsetMatrix_ = Urho3D::Matrix3x4( -bone.initialPosition_, bone.initialRotation_, bone.initialScale_ );
bones.Push( bone );
}
skeleton.SetRootBoneIndex( model->GetRootBoneIndex() );
The problem I face is that the model is being occluded, as if the bounding box is outside the frustum. If I move the camera to a specific angle in the scene, then the model renders. I believe this has to do with the bone position and offset code above, but I’m not exactly sure what I could be doing wrong. When I enable the debug render, the skeleton is being drawn where it should be at the correct positions, but I never see the bounding box for the model being drawn.
If I opt not to set any bones in the skeleton and supply an empty skeleton to the model, the model will be rendered without any occlusion problems with the frustum.
Since the bone positions in the data are in world-space, is there some other adjustment or change I need to make to the code above that I didn’t account for this?