public Assimp.Animation assimpExport(ref Assimp.Scene scn) { Assimp.Animation asAnim = new Assimp.Animation(); asAnim.Name = Anim; //Make sure keyframe data is loaded from the files if (!loaded) { fetchAnimMetaData(); loaded = true; } asAnim.TicksPerSecond = 60; asAnim.DurationInTicks = animMeta.FrameCount; float time_interval = 1.0f / (float)asAnim.TicksPerSecond; //Add Node-Bone Channels for (int i = 0; i < animMeta.NodeCount; i++) { string name = animMeta.NodeData[i].Node; Assimp.NodeAnimationChannel mChannel = new Assimp.NodeAnimationChannel(); mChannel.NodeName = name; //mChannel.PostState = Assimp.AnimationBehaviour.Linear; //mChannel.PreState = Assimp.AnimationBehaviour.Linear; //Export Keyframe Data for (int j = 0; j < animMeta.FrameCount; j++) { //Position Assimp.VectorKey vk = new Assimp.VectorKey(j * time_interval, MathUtils.convertVector(animMeta.anim_positions[name][j])); mChannel.PositionKeys.Add(vk); //Rotation Assimp.QuaternionKey qk = new Assimp.QuaternionKey(j * time_interval, MathUtils.convertQuaternion(animMeta.anim_rotations[name][j])); mChannel.RotationKeys.Add(qk); //Scale Assimp.VectorKey sk = new Assimp.VectorKey(j * time_interval, MathUtils.convertVector(animMeta.anim_scales[name][j])); mChannel.ScalingKeys.Add(sk); } asAnim.NodeAnimationChannels.Add(mChannel); } return(asAnim); }
private Keyframe[][] GenerateTranslationTrack(List <Assimp.VectorKey> keys, Bone bone) { Keyframe[] x_track = new Keyframe[keys.Count]; Keyframe[] y_track = new Keyframe[keys.Count]; Keyframe[] z_track = new Keyframe[keys.Count]; for (int i = 0; i < keys.Count; i++) { Assimp.VectorKey current_key = keys[i]; Vector3 value = new Vector3(current_key.Value.X, current_key.Value.Y, current_key.Value.Z); x_track[i].Key = value.X; x_track[i].Time = (float)current_key.Time; y_track[i].Key = value.Y; y_track[i].Time = (float)current_key.Time; z_track[i].Key = value.Z; z_track[i].Time = (float)current_key.Time; } return(new Keyframe[][] { x_track, y_track, z_track }); }
/// <summary> /// Set the new position in Assimp Database for export /// </summary> /// <param name="joint">joint with position</param> public void SetNewJointPosition(Joint joint) { Assimp.NodeAnimationChannel nodeChannel = assimpAnimation.NodeAnimationChannels.FindNodeByName(joint.Name); if (nodeChannel != null) { // TODO : Check here Assimp.Vector3D newPoint = joint.GetAssimpPoint(); Assimp.VectorKey[] newPositionKeys = new Assimp.VectorKey[nodeChannel.PositionKeyCount]; nodeChannel.PositionKeys.CopyTo(newPositionKeys); newPositionKeys[Tick].Value = newPoint; nodeChannel.PositionKeys.Clear(); nodeChannel.PositionKeys.AddRange(newPositionKeys); } }