Пример #1
0
 /**
  * @private
  */
 protected override void _onClear()
 {
     type           = null;
     name           = null;
     frame          = null;
     data           = null;
     armature       = null;
     bone           = null;
     slot           = null;
     animationState = null;
 }
Пример #2
0
        private void RenderAnimationNode(AnimationNodeData node)
        {
            Matrix4 lastMatrix = currentMatrix;

            if (node.ChildNode != null)
            {
                RenderAnimationNode(node.ChildNode);
            }

            if (node.FirstAnimationFrameID != -1)
            {
                AnimationFrameData animFrame = node.AnimationFrames.LastOrDefault(x => animCounter >= x.FrameTime);

                maxCounter = Math.Max(maxCounter, node.AnimationFrames.Max(x => x.FrameTime) * 3);

                if (animFrame != null)
                {
                    Vector2 nodeOffset = Vector2.Zero;
                    if ((node.Unknown0x06 & 0x01) == 0x01)
                    {
                        nodeOffset.X = animFrame.Transform.TransformOffset.Offset.X;
                        nodeOffset.Y = animFrame.Transform.TransformOffset.Offset.Y;
                    }
                    else
                    {
                        nodeOffset.X = -animFrame.Transform.TransformOffset.Offset.X;
                        nodeOffset.Y = -animFrame.Transform.TransformOffset.Offset.Y;
                    }

                    RenderAnimationFrame(animFrame, nodeOffset);
                }
            }

            if (node.SiblingNode != null)
            {
                RenderAnimationNode(node.SiblingNode);
            }

            currentMatrix = lastMatrix;
        }
Пример #3
0
        private void RenderAnimationFrame(AnimationFrameData animFrame, Vector2 offset)
        {
            float scaleX = (animFrame.Transform.Scale.X / 100.0f);
            float scaleY = (animFrame.Transform.Scale.Y / 100.0f);

            if (scaleX == 0.0f || scaleY == 0.0f)
            {
                return;
            }

            Matrix4 translationMatrix = Matrix4.CreateTranslation((animFrame.Transform.BaseOffset.X + offset.X), (animFrame.Transform.BaseOffset.Y + offset.Y), 0.0f);
            Matrix4 rotationMatrix    = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(animFrame.Transform.RotationAngle));
            Matrix4 scaleMatrix       = Matrix4.CreateScale(scaleX, scaleY, 1.0f);

            currentMatrix = Matrix4.Mult(translationMatrix, currentMatrix);

            if (animFrame.Unknown0x02 != 1)
            {
                currentMatrix = Matrix4.Mult(Matrix4.CreateTranslation((animFrame.Sprite.Rectangle.Width / 2), (animFrame.Sprite.Rectangle.Height / 2), 0.0f), currentMatrix);
            }

            currentMatrix = Matrix4.Mult(rotationMatrix, currentMatrix);
            currentMatrix = Matrix4.Mult(scaleMatrix, currentMatrix);

            if (animFrame.Unknown0x02 != 1)
            {
                currentMatrix = Matrix4.Mult(Matrix4.CreateTranslation(-(animFrame.Sprite.Rectangle.Width / 2), -(animFrame.Sprite.Rectangle.Height / 2), 0.0f), currentMatrix);
            }

            glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "objectMatrix", false, currentMatrix);

            string spriteName = animFrame.Sprite.PrepareRender(glHelper);

            glHelper.Textures.ActivateTexture(spriteName, TextureUnit.Texture0);
            glHelper.Buffers.Render(spriteName);
        }
Пример #4
0
        private void Render()
        {
            if (selectedObj != null)
            {
                if (render3D)
                {
                    glHelper.Camera.Update();

                    /* Set projection, modelview */
                    glHelper.ProjectionType = ProjectionType.Perspective;
                    glHelper.ZNear          = 0.01f;
                    glHelper.ZFar           = 1000.0f;

                    /* Activate default shader */
                    glHelper.Shaders.ActivateProgram(Rendering.DefaultShaderName);

                    /* Set shader uniforms */
                    glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "projectionMatrix", false, glHelper.CreateProjectionMatrix());
                    glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "modelviewMatrix", false, Matrix4.Identity);
                    glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "objectMatrix", false, Matrix4.Identity);
                    glHelper.Shaders.SetUniform(Rendering.DefaultShaderName, "cameraPosition", glHelper.Camera.Position);
                    glHelper.Shaders.SetUniform(Rendering.DefaultShaderName, "enableLight", Convert.ToInt32(Properties.Settings.Default.EnableLighting));

                    if (Properties.Settings.Default.EnableLighting)
                    {
                        Rendering.ApplyLightRotation();
                        Rendering.UpdateLightUniforms(Rendering.DefaultShaderName, "numLights", "lights");
                    }

                    /* Render each known object */
                    foreach (string glObjectName in glObjectNames)
                    {
                        /* Activate object's texture */
                        glHelper.Textures.ActivateTexture(glObjectName, TextureUnit.Texture0);

                        if (glObjectMatrixMap.ContainsKey(glObjectName))
                        {
                            glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "objectMatrix", false, glObjectMatrixMap[glObjectName]);
                        }

                        /* Render */
                        glHelper.Buffers.Render(glObjectName);
                    }

                    /* Render light visualization */
                    if (Properties.Settings.Default.EnableLighting)
                    {
                        Rendering.RenderLightVisualization();
                    }
                }
                else
                {
                    Matrix4 modelviewMatrix2D        = Matrix4.CreateTranslation((glHelper.Viewport.Width / 2), (glHelper.Viewport.Height / 2), 0.0f);
                    Matrix4 modelviewWithImageOffset = Matrix4.Mult(modelviewMatrix2D, Matrix4.CreateTranslation(imageOffset.X, imageOffset.Y, 0.0f));

                    /* Set projection, modelview */
                    glHelper.ProjectionType = ProjectionType.Orthographic;
                    glHelper.ZNear          = -10.0f;
                    glHelper.ZFar           = 10.0f;

                    /* Activate empty dummy texture */
                    glHelper.Textures.ActivateTexture(Rendering.EmptyTextureName, TextureUnit.Texture0);

                    /* Activate default shader */
                    glHelper.Shaders.ActivateProgram(Rendering.DefaultShaderName);

                    /* Set shader uniforms */
                    glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "projectionMatrix", false, glHelper.CreateProjectionMatrix());
                    glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "modelviewMatrix", false, modelviewMatrix2D);
                    glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "objectMatrix", false, Matrix4.Identity);
                    glHelper.Shaders.SetUniform(Rendering.DefaultShaderName, "enableLight", 0);

                    /* Render */
                    glHelper.Buffers.Render(Rendering.AxisMarkerObjectName);

                    if (selectedObj != null)
                    {
                        /* Set shader uniforms */
                        glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "modelviewMatrix", false, modelviewWithImageOffset);

                        if (selectedObj is AnimationData)
                        {
                            /* Render animation */
                            AnimationData anim = (selectedObj as AnimationData);
                            if (anim.FirstNode != null)
                            {
                                currentMatrix = Matrix4.Identity;
                                RenderAnimationNode(anim.FirstNode);
                            }
                        }
                        else if (selectedObj is AnimationFrameData)
                        {
                            AnimationFrameData animFrame = (selectedObj as AnimationFrameData);
                            currentMatrix = Matrix4.Identity;
                            RenderAnimationFrame(animFrame, Vector2.Zero);
                        }
                        else if (selectedObj is ImageInformation || selectedObj is SpriteData || selectedObj is TxpImage)
                        {
                            foreach (string glObjectName in glObjectNames)
                            {
                                /* Activate object's texture */
                                glHelper.Textures.ActivateTexture(glObjectName, TextureUnit.Texture0);

                                /* Set matrices */
                                Matrix4 translationMatrix = Matrix4.Identity;
                                if (selectedObj is ImageInformation)
                                {
                                    ImageInformation image = (selectedObj as ImageInformation);
                                    translationMatrix = Matrix4.CreateTranslation(-(image.Bitmap.Width / 2), -(image.Bitmap.Height / 2), 0.0f);
                                }
                                else if (selectedObj is SpriteData)
                                {
                                    SpriteData sprite = (selectedObj as SpriteData);
                                    translationMatrix = Matrix4.CreateTranslation(-(sprite.Image.Width / 2), -(sprite.Image.Height / 2), 0.0f);
                                }
                                else if (selectedObj is TxpImage)
                                {
                                    TxpImage txp = (selectedObj as TxpImage);
                                    translationMatrix = Matrix4.CreateTranslation(-(txp.Image.Width / 2), -(txp.Image.Height / 2), 0.0f);
                                }
                                glHelper.Shaders.SetUniformMatrix(Rendering.DefaultShaderName, "objectMatrix", false, translationMatrix);

                                /* Render object */
                                glHelper.Buffers.Render(glObjectName);
                            }
                        }
                    }
                }
            }
        }