Unit test for VmdlWriter.Build. It constructs a ModelBuildContext with meshes, materials, attachments, bodygroups and animations, calls VmdlWriter.Build and asserts the generated KV3 text contains expected class entries and filenames.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GmodAssetImporter;
[TestClass]
public class VmdlWriterTests
{
[TestMethod]
public void EmitsKv3HeaderRenderMeshAndBindPose()
{
var ctx = new ModelBuildContext
{
ModelAssetDirectory = "models/test",
IncludeBindPose = true,
Meshes =
{
new MeshExport { Name = "body", FileName = "body.fbx" }
},
MaterialRemaps =
{
new MaterialRemap { From = "gun.vmat", To = "materials/gun.vmat" }
},
Attachments =
{
new AttachmentData { Name = "muzzle", ParentBone = "ValveBiped.muzzle", Origin = new Vec3( 1, 2, 3 ) }
},
BodyGroups =
{
new ImporterBodyGroup
{
Name = "magazine",
Choices =
{
new ImporterBodyGroupChoice { Name = "default", MeshNames = { "body" } }
}
}
},
Animations =
{
new AnimationClip { Name = "idle", FileName = "anim_idle.smd", FrameRate = 30, Looping = true }
}
};
var text = VmdlWriter.Build( ctx );
Assert.IsTrue( text.StartsWith( "<!-- kv3" ) );
Assert.IsTrue( text.Contains( "_class = \"RenderMeshFile\"" ) );
Assert.IsTrue( text.Contains( "filename = \"models/test/body.fbx\"" ) );
Assert.IsTrue( text.Contains( "_class = \"AnimBindPose\"" ) );
Assert.IsTrue( text.Contains( "_class = \"Attachment\"" ) );
Assert.IsTrue( text.Contains( "name = \"muzzle\"" ) );
Assert.IsTrue( text.Contains( "_class = \"BodyGroup\"" ) );
Assert.IsTrue( text.Contains( "_class = \"AnimFile\"" ) );
Assert.IsTrue( text.Contains( "source_filename = \"models/test/anim_idle.smd\"" ) );
Assert.IsTrue( text.Contains( "from = \"gun.vmat\"" ) );
Assert.IsTrue( text.Contains( "to = \"materials/gun.vmat\"" ) );
}
}