示例#1
0
        private void setToOptimalSize()
        {
            // get model component and image size
            int            imageWidth     = 0;
            int            imageHeight    = 0;
            ModelComponent modelComponent =
                m_gameObject.GetComponent(typeof(ModelComponent).ToString()) as ModelComponent;
            CatModelInstance modelInstance = modelComponent.GetCatModelInstance();

            if (modelInstance == null || modelInstance.GetMaterial() == null)
            {
                return;
            }
            CatTexture texture = (CatTexture)(modelInstance.GetMaterial().GetParameter("DiffuseMap"));

            imageWidth  = texture.value.Width;
            imageHeight = texture.value.Height;

            if (modelComponent.Model.GetAnimation() != null)
            {
                imageWidth  /= modelComponent.Model.GetAnimation().m_tiltUV.X;
                imageHeight /= modelComponent.Model.GetAnimation().m_tiltUV.Y;
            }

            // get Camera Min Width
            float cameraMinWidth = Mgr <Camera> .Singleton.ViewSize.X;
            // get Screen Width
            float screenWidth = Mgr <Camera> .Singleton.targetResolutionWidth;

            // calculate optimalWidth
            Size = new Vector2(imageWidth * cameraMinWidth / screenWidth,
                               imageHeight * cameraMinWidth / screenWidth);
        }
示例#2
0
        public void fadeToAnimation(String animationClipName)
        {
            // cur_index
            ModelComponent modelComponent = (ModelComponent)m_gameObject.GetComponent(typeof(ModelComponent).Name);

            if (modelComponent == null)
            {
                Console.Out.WriteLine("No ModelComponent for Animator.");
                return;
            }
            Animation     animation      = modelComponent.Model.GetAnimation();
            AnimationClip cur_clip       = animation.getAnimationClip(m_currentAnimationName);
            int           cur_beginIndex = cur_clip.m_beginIndex;
            int           cur_endIndex   = cur_clip.m_endIndex;
            // target index
            AnimationClip target_clip = animation.getAnimationClip(animationClipName);

            if (target_clip != null)
            {
                int target_beginIndex = target_clip.m_beginIndex;
                int target_endIndex   = target_clip.m_endIndex;

                int index = target_beginIndex
                            + (int)((target_endIndex - target_beginIndex + 1) * (float)(m_currentIndex - cur_beginIndex) / (cur_endIndex - cur_beginIndex + 1));
                m_currentIndex         = index;
                m_currentAnimationName = animationClipName;
                m_isPlaying.SetValue(true);
            }
        }
示例#3
0
        public override CatModelInstance GetModel()
        {
            ModelComponent modelComponent = (ModelComponent)m_gameObject
                                            .GetComponent(typeof(ModelComponent).ToString());

            return(modelComponent.GetCatModelInstance());
        }
示例#4
0
        protected override void PostClone(Serialable _object)
        {
            ModelComponent target = _object as ModelComponent;

            m_model = target.Model;
            if (target.m_catModelInstance != null)
            {
                m_catModelInstance = target.m_catModelInstance.Clone();
            }
        }
示例#5
0
        public void RunScript()
        {
            GameObject newGameObject = new GameObject();

            newGameObject.Position = (new CatVector3(Vector3.Zero));
            ModelComponent modelComponent = new ModelComponent(newGameObject);

            newGameObject.AddComponent(modelComponent);
            QuadRender quadRender = new QuadRender(newGameObject);

            newGameObject.AddComponent(quadRender);
            Mgr <Scene> .Singleton._gameObjectList.AddGameObject(newGameObject);
        }
示例#6
0
        public override void Update(int timeLastFrame)
        {
            base.Update(timeLastFrame);

            Environment environment = m_gameObject.Scene.GetSharedObject(typeof(Environment).ToString())
                                      as Environment;
            ModelComponent modelComponent = m_gameObject.GetComponent(typeof(ModelComponent))
                                            as ModelComponent;

            if (environment != null && modelComponent != null &&
                modelComponent.GetCatModelInstance() != null &&
                modelComponent.GetCatModelInstance().GetMaterial().HasParameter("Time"))
            {
                modelComponent.GetCatModelInstance().GetMaterial()
                .SetParameter("Time", new CatFloat(environment.CurrentTimeInRatio));
            }
        }
示例#7
0
        public void Draw(int timeLastFrame)
        {
            if (!Enable)
            {
                return;
            }

            ModelComponent modelComponent = (ModelComponent)m_gameObject.GetComponent(typeof(ModelComponent).ToString());

            Mgr <GraphicsDevice> .Singleton.SetVertexBuffer(m_vertexBuffer);

            // configure effect

            Effect effect = null;

            if (modelComponent != null && modelComponent.Model != null)
            {
                CatMaterial material = modelComponent.GetCatModelInstance().GetMaterial();
                material.SetParameter("World", new CatMatrix(m_gameObject.AbsTransform));
                material.SetParameter("View", new CatMatrix(Mgr <Camera> .Singleton.View));
                material.SetParameter("Projection", new CatMatrix(Mgr <Camera> .Singleton.m_projection));
                if (material.HasParameter("LightMap") && Mgr <Scene> .Singleton.m_shadowSystem != null)
                {
                    material.SetParameter("LightMap", new CatTexture(Mgr <Scene> .Singleton.m_shadowSystem.AccumulateLight));
                }
                effect = material.ApplyMaterial();
            }
            else
            {
                effect = Mgr <DebugTools> .Singleton.DrawEffect;
                ((BasicEffect)effect).Alpha              = 1.0f;
                ((BasicEffect)effect).DiffuseColor       = new Vector3(1.0f, 0.0f, 1.0f);
                ((BasicEffect)effect).View               = Mgr <Camera> .Singleton.View;
                ((BasicEffect)effect).Projection         = Mgr <Camera> .Singleton.m_projection;
                ((BasicEffect)effect).VertexColorEnabled = false;
                ((BasicEffect)effect).World              = m_gameObject.AbsTransform;
            }
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Mgr <GraphicsDevice> .Singleton.DrawUserPrimitives <VertexPositionColorTexture>(
                    PrimitiveType.TriangleStrip, m_vertex, 0, 2);
            }
        }
示例#8
0
        public void Draw(int timeLastFrame)
        {
            if (m_lifeInMS <= 0)
            {
                return;
            }

            // now just take it as basic effect
            Mgr <GraphicsDevice> .Singleton.SetVertexBuffer(m_emitter.m_vertexBuffer);

            ModelComponent modelComponent = (ModelComponent)m_emitter.GameObject.
                                            GetComponent(typeof(ModelComponent));
            Effect effect      = null;
            Matrix matPosition = Matrix.CreateTranslation(position);
            Matrix matRotation = Matrix.CreateRotationZ(m_rotationZ);
            Matrix matScale    = Matrix.CreateScale(m_size.X, m_size.Y, 1.0f);
            Matrix transform   = Matrix.Multiply(Matrix.Multiply(matScale, matRotation), matPosition);

            if (modelComponent != null && modelComponent.Model != null)
            {
                CatMaterial material = modelComponent.GetCatModelInstance().GetMaterial();
                material.SetParameter("Alpha", new CatFloat((float)m_lifeInMS / m_emitter.ParticleLifetimeInMS));
                material.SetParameter("World", new CatMatrix(transform));
                material.SetParameter("View", new CatMatrix(Mgr <Camera> .Singleton.View));
                material.SetParameter("Projection", new CatMatrix(Mgr <Camera> .Singleton.m_projection));
                effect = material.ApplyMaterial();
            }
            else
            {
                effect = Mgr <DebugTools> .Singleton.DrawEffect;
                ((BasicEffect)effect).Alpha              = (float)m_lifeInMS / m_emitter.ParticleLifetimeInMS;
                ((BasicEffect)effect).DiffuseColor       = new Vector3(1.0f, 0.0f, 1.0f);
                ((BasicEffect)effect).View               = Mgr <Camera> .Singleton.View;
                ((BasicEffect)effect).Projection         = Mgr <Camera> .Singleton.m_projection;
                ((BasicEffect)effect).VertexColorEnabled = false;
                ((BasicEffect)effect).World              = transform;
            }
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Mgr <GraphicsDevice> .Singleton.DrawUserPrimitives <VertexPositionTexture>(
                    PrimitiveType.TriangleStrip, m_emitter.m_vertex, 0, 2);
            }
        }
示例#9
0
        public void PlayAnimation(String animationClipName)
        {
            ModelComponent modelComponent = (ModelComponent)m_gameObject.GetComponent(typeof(ModelComponent).ToString());

            if (modelComponent == null || modelComponent.Model == null)
            {
                return;
            }
            Animation     animation   = modelComponent.Model.GetAnimation();
            AnimationClip target_clip = animation.getAnimationClip(animationClipName);

            if (target_clip == null)
            {
                return;
            }
            m_currentIndex         = target_clip.m_beginIndex;
            m_currentAnimationName = animationClipName;
            m_isPlaying.SetValue(true);
        }
示例#10
0
//         public override CatComponent CloneComponent(GameObject gameObject)
//         {
//             Animator animator = new Animator(gameObject);
//             animator.AnimationName = m_currentAnimationName;
//             return animator;
//         }

        // needs: quadRender, quadRender.Animation, Model,

        public override void Initialize(Scene scene)
        {
            base.Initialize(scene);

            // configuration
            ModelComponent modelComponent = (ModelComponent)m_gameObject.GetComponent(typeof(ModelComponent).Name);

            if (modelComponent == null || modelComponent.Model == null)
            {
                return;
            }
            Animation animation = modelComponent.Model.GetAnimation();

            m_timeLastFrame = 0;
            m_isPlaying.SetValue(animation.m_isAutoPlay);
            m_currentIndex = 0;
            if (m_currentAnimationName == null || m_currentAnimationName == "")
            {
                m_currentAnimationName = animation.m_defaultAnimationClipName;
            }
            m_isPong = false;
            m_millionSecondPreFrame.SetValue(animation.m_millionSecondPerFrame);
        }
示例#11
0
        public void RunScript()
        {
            if (Mgr <CatProject> .Singleton == null)
            {
                return;
            }
            // ask for model
            string modelName = ResourceSelectorWindow.SelectResource(ResourceSelectorWindow.ObserveType.Model,
                                                                     "");

            if (modelName == "")
            {
                return;
            }
            CatModel model = Mgr <CatProject> .Singleton.modelList1.GetModel(modelName);

            if (model != null)
            {
                CatMaterial material = model.GetMaterial();
                if (material == null || !material.HasParameter("DiffuseMap"))
                {
                    // TODO: give warning
                    return;
                }
            }
            else
            {
                return;
            }
            // ask for texture
            string textureName = ResourceSelectorWindow.SelectResource(ResourceSelectorWindow.ObserveType.Texture,
                                                                       "");

            if (textureName == "")
            {
                return;
            }
            Texture2D texture = Mgr <CatProject> .Singleton.contentManger.Load <Texture2D>("image\\" + textureName);

            if (texture == null)
            {
                return;
            }

            GameObject newGameObject = new GameObject();

            if (Mgr <Camera> .Singleton != null)
            {
                newGameObject.Position = new Vector3(Mgr <Camera> .Singleton.TargetPosition.X,
                                                     Mgr <Camera> .Singleton.TargetPosition.Y,
                                                     0.0f);
            }
            else
            {
                newGameObject.Position = Vector3.Zero;
            }
            ModelComponent modelComponent = new ModelComponent(newGameObject);

            newGameObject.AddComponent(modelComponent);
            modelComponent.Model = model;
            modelComponent.GetCatModelInstance().GetMaterial().SetParameter("DiffuseMap",
                                                                            new CatTexture(texture));
            QuadRender quadRender = new QuadRender(newGameObject);

            newGameObject.AddComponent(quadRender);
            quadRender.OptimalSize = true;
            Mgr <Scene> .Singleton._gameObjectList.AddGameObject(newGameObject);
        }
示例#12
0
        public override void Update(int timeLastFrame)
        {
            base.Update(timeLastFrame);

            ModelComponent modelComponent = (ModelComponent)m_gameObject.GetComponent(typeof(ModelComponent).ToString());

            if (modelComponent == null)
            {
                Console.Out.WriteLine("No ModelComponent for Animator.");
                return;
            }

            Animation  animation  = modelComponent.Model.GetAnimation();
            QuadRender quadRender = (QuadRender)m_gameObject.GetComponent(typeof(QuadRender).ToString());

            float width_per_frame  = 1.0f / animation.m_tiltUV.X;
            float height_per_frame = 1.0f / animation.m_tiltUV.Y;

            if (m_isPlaying)
            {
                m_timeLastFrame += timeLastFrame;
            }

            if (m_timeLastFrame >= m_millionSecondPreFrame)
            {
                m_timeLastFrame -= m_millionSecondPreFrame;
                AnimationClip current_clip = animation.getAnimationClip(m_currentAnimationName);
                if (current_clip == null)
                {
                    Console.WriteLine("Error! Can not find animation clip: " + m_currentAnimationName);
                    return;
                }
                if (current_clip.m_mode == AnimationClip.PlayMode.PINGPONG)
                {
                    if (!m_isPong) // ping
                    {
                        if (m_currentIndex < current_clip.m_endIndex)
                        {
                            ++m_currentIndex;
                        }
                        else
                        {
                            --m_currentIndex;
                            m_isPong = true;
                        }
                    }
                    else
                    { // pong
                        if (m_currentIndex > current_clip.m_beginIndex)
                        {
                            --m_currentIndex;
                        }
                        else
                        {
                            ++m_currentIndex;
                            m_isPong = false;
                        }
                    }
                }
                else
                {
                    if (m_currentIndex < current_clip.m_endIndex)
                    {
                        ++m_currentIndex;
                    }
                    else
                    {
                        if (current_clip.m_mode == AnimationClip.PlayMode.CLAMP)
                        {
                            m_isPlaying.SetValue(false);
                        }
                        else if (current_clip.m_mode == AnimationClip.PlayMode.LOOP)
                        {
                            m_currentIndex = current_clip.m_beginIndex;
                        }
                        else if (current_clip.m_mode == AnimationClip.PlayMode.STOP)
                        {
                            m_currentIndex = current_clip.m_beginIndex;
                            m_isPlaying.SetValue(false);
                        }
                    }
                }
            }

            Point current_nxm = new Point();

            current_nxm.X = m_currentIndex % animation.m_tiltUV.X;
            current_nxm.Y = m_currentIndex / animation.m_tiltUV.X;

            quadRender.m_vertex[0].TextureCoordinate.X = current_nxm.X * width_per_frame;
            quadRender.m_vertex[0].TextureCoordinate.Y = (current_nxm.Y + 1) * height_per_frame;
            quadRender.m_vertex[1].TextureCoordinate.X = current_nxm.X * width_per_frame;
            quadRender.m_vertex[1].TextureCoordinate.Y = current_nxm.Y * height_per_frame;
            quadRender.m_vertex[2].TextureCoordinate.X = (current_nxm.X + 1) * width_per_frame;
            quadRender.m_vertex[2].TextureCoordinate.Y = (current_nxm.Y + 1) * height_per_frame;
            quadRender.m_vertex[3].TextureCoordinate.X = (current_nxm.X + 1) * width_per_frame;
            quadRender.m_vertex[3].TextureCoordinate.Y = current_nxm.Y * height_per_frame;
        }