public void Convert(ModelDocument model, CIwResGroup group) { this.group = group; this.modelMesh = new CIwModel(); modelMesh.Name = model.Name; group.AddRes(new CIwTexture() { FilePath = "../textures/checkers.png" }); group.AddRes(modelMesh); var mesh = new CMesh(); mesh.Scale = 1.0f / scale; modelMesh.ModelBlocks.Add(mesh); writer = new ModelWriter(modelMesh); WriteSkeleton(model); WriteMaterials(model); //WriteMesh(model.Meshes[1]); foreach (var m in model.Meshes) { WriteMesh(m); //break; } WriteAnimations(model,modelMesh); }
private void WriteAnimations(ModelDocument model, CIwModel modelMesh) { if (model.Animations == null || model.Animations.Count == 0) return; modelMesh.Skin.Animations = new List<CIwAnim>(); foreach (var a in model.Animations) { var anim = new CIwAnim() { Name = a.Name, skeleton=modelMesh.Skin.skeleton }; if (a.Frames != null) foreach (var f in a.Frames) { var frame = new CIwAnimKeyFrame(); frame.time = f.Time; foreach (var b in f.Bones) { var bone = new CIwAnimKeyFrameBone(); bone.bone = b.Bone.Name; bone.pos = GetVec3(b.Position); bone.rot = GetQuat(b.Rotation); frame.bones.Add(bone); } anim.KeyFrames.Add(frame); } modelMesh.Skin.Animations.Add(anim); } }