/// <summary> /// Prepara una nueva animacion para ser ejecutada /// </summary> private void initAnimationSettings(string animationName, bool playLoop, float userFrameRate) { isAnimating = true; currentAnimation = animations[animationName]; this.playLoop = playLoop; currentTime = 0; currentFrame = 0; //Cambiar BoundingBox boundingBox = currentAnimation.BoundingBox; updateBoundingBox(); //Si el usuario no especifico un FrameRate, tomar el default de la animacion if (userFrameRate == -1f) { frameRate = (float)currentAnimation.Data.frameRate; } else { frameRate = userFrameRate; } //La duracion de la animacion. animationTimeLenght = (float)currentAnimation.Data.framesCount / frameRate; }
/// <summary> /// Cargar datos iniciales /// </summary> private void initData(Mesh mesh, string name, MeshRenderType renderType, OriginalData originalData) { this.d3dMesh = mesh; this.name = name; this.renderType = renderType; this.originalData = originalData; this.enabled = false; this.autoUpdateBoundingBox = true; this.meshInstances = new List <TgcKeyFrameMesh>(); this.alphaBlendEnable = false; vertexDeclaration = new VertexDeclaration(mesh.Device, mesh.Declaration); //variables de movimiento this.autoTransformEnable = true; this.translation = new Vector3(0f, 0f, 0f); this.rotation = new Vector3(0f, 0f, 0f); this.scale = new Vector3(1f, 1f, 1f); this.transform = Matrix.Identity; //variables de animacion this.isAnimating = false; this.currentAnimation = null; this.playLoop = false; this.currentTime = 0f; this.currentFrame = 0; this.animationTimeLenght = 0f; this.animations = new Dictionary <string, TgcKeyFrameAnimation>(); //Shader this.effect = GuiController.Instance.Shaders.TgcKeyFrameMeshShader; this.technique = GuiController.Instance.Shaders.getTgcKeyFrameMeshTechnique(this.renderType); }
/// <summary> /// Carga una animación a un modelo ya cargado, a partir de un objeto TgcKeyFrameAnimationData ya parseado /// La animación se agrega al modelo. /// </summary> /// <param name="mesh">Modelo ya cargado</param> /// <param name="animationData">Objeto de animacion con datos ya cargados</param> public TgcKeyFrameAnimation loadAnimation(TgcKeyFrameMesh mesh, TgcKeyFrameAnimationData animationData) { //BoundingBox de la animación, aprovechar lo que viene en el XML o utilizar el de la malla estática TgcBoundingBox boundingBox = null; if (animationData.pMin != null && animationData.pMax != null) { boundingBox = new TgcBoundingBox( TgcParserUtils.float3ArrayToVector3(animationData.pMin), TgcParserUtils.float3ArrayToVector3(animationData.pMax)); } else { boundingBox = mesh.BoundingBox; } TgcKeyFrameAnimation animation = new TgcKeyFrameAnimation(animationData, boundingBox); mesh.Animations.Add(animationData.name, animation); return(animation); }
/// <summary> /// Prepara una nueva animacion para ser ejecutada /// </summary> private void initAnimationSettings(string animationName, bool playLoop, float userFrameRate) { isAnimating = true; currentAnimation = animations[animationName]; this.playLoop = playLoop; currentTime = 0; currentFrame = 0; //Cambiar BoundingBox boundingBox = currentAnimation.BoundingBox; updateBoundingBox(); //Si el usuario no especifico un FrameRate, tomar el default de la animacion if (userFrameRate == -1f) { frameRate = (float)currentAnimation.Data.frameRate; } else { frameRate = userFrameRate; } //La duracion de la animacion. animationTimeLenght = (float)currentAnimation.Data.framesCount / frameRate; }
/// <summary> /// Cargar datos iniciales /// </summary> private void initData(Mesh mesh, string name, MeshRenderType renderType, OriginalData originalData) { this.d3dMesh = mesh; this.name = name; this.renderType = renderType; this.originalData = originalData; this.enabled = false; this.autoUpdateBoundingBox = true; this.meshInstances = new List<TgcKeyFrameMesh>(); this.alphaBlendEnable = false; vertexDeclaration = new VertexDeclaration(mesh.Device, mesh.Declaration); //variables de movimiento this.autoTransformEnable = true; this.translation = new Vector3(0f, 0f, 0f); this.rotation = new Vector3(0f, 0f, 0f); this.scale = new Vector3(1f, 1f, 1f); this.transform = Matrix.Identity; //variables de animacion this.isAnimating = false; this.currentAnimation = null; this.playLoop = false; this.currentTime = 0f; this.currentFrame = 0; this.animationTimeLenght = 0f; this.animations = new Dictionary<string, TgcKeyFrameAnimation>(); }
/// <summary> /// Carga una animación a un modelo ya cargado, a partir de un objeto TgcKeyFrameAnimationData ya parseado /// La animación se agrega al modelo. /// </summary> /// <param name="mesh">Modelo ya cargado</param> /// <param name="animationData">Objeto de animacion con datos ya cargados</param> public TgcKeyFrameAnimation loadAnimation(TgcKeyFrameMesh mesh, TgcKeyFrameAnimationData animationData) { //BoundingBox de la animación, aprovechar lo que viene en el XML o utilizar el de la malla estática TgcBoundingBox boundingBox = null; if (animationData.pMin != null && animationData.pMax != null) { boundingBox = new TgcBoundingBox( TgcParserUtils.float3ArrayToVector3(animationData.pMin), TgcParserUtils.float3ArrayToVector3(animationData.pMax)); } else { boundingBox = mesh.BoundingBox; } TgcKeyFrameAnimation animation = new TgcKeyFrameAnimation(animationData, boundingBox); mesh.Animations.Add(animationData.name, animation); return animation; }