Beispiel #1
0
        public static Matrix ProjectionMapping(
            int ref_camera,
            SCN0Node node,
            ModelPanelViewport v,
            float frame)
        {
            Matrix   projMtx = Matrix.Identity;
            Matrix   camMtx  = Matrix.Identity;
            GLCamera cam     = v.Camera;

            if (ref_camera >= 0 && node?.CameraGroup != null && ref_camera < node.CameraGroup.Children.Count)
            {
                // Set so that the image is projected from the specified camera.
                // Transform to the viewing coordinate system of the specified camera
                SCN0CameraNode camNode = (SCN0CameraNode)node.CameraGroup.Children[ref_camera];
                camNode.GetModelViewMatrix(frame, out Matrix cm, out Matrix cmInv);
                camMtx  = cm * cam._matrix;
                projMtx = (Matrix)ProjectionTexMtx(camNode, frame);
            }
            else
            {
                camMtx  = cam._matrix;
                projMtx = (Matrix)ProjectionTexMtx(cam);
            }

            return(projMtx * camMtx);
        }
Beispiel #2
0
        public static Matrix EnvCamMap(int refCam, SCN0Node node, ModelPanelViewport v, float frame)
        {
            GLCamera cam = v.Camera;

            if (refCam >= 0 && node?.CameraGroup != null && refCam < node.CameraGroup.Children.Count)
            {
                SCN0CameraNode camNode = (SCN0CameraNode)node.CameraGroup.Children[refCam];
                camNode.GetModelViewMatrix(frame, out Matrix cm, out Matrix cmInv);
                return((Matrix)EnvironmentTexMtx() * cm.GetRotationMatrix());
            }

            return((Matrix)EnvironmentTexMtx() * v.Camera._matrix.GetRotationMatrix());
        }
Beispiel #3
0
        public void SetFrame(int index)
        {
            if (index > _maxFrame || index < 0)
            {
                return;
            }

            index = TargetModel == null ? 0 : index;

            CurrentFrame = index;

            if (stPersonToolStripMenuItem.Checked && _scn0 != null && scn0Editor._camera != null)
            {
                SCN0CameraNode       c = scn0Editor._camera;
                CameraAnimationFrame f = c.GetAnimFrame(index - 1);
                Vector3 r = f.GetRotate(index, c.Type);
                Vector3 t = f.Pos;
                ModelPanel._camera.Reset();
                ModelPanel._camera.Translate(t._x, t._y, t._z);
                ModelPanel._camera.Rotate(r._x, r._y, r._z);
                ModelPanel._aspect = f.Aspect;
                ModelPanel._farZ   = f.FarZ;
                ModelPanel._nearZ  = f.NearZ;
                ModelPanel._fovY   = f.FovY;
                ModelPanel.OnResized();
            }

            pnlPlayback.btnNextFrame.Enabled = _animFrame < _maxFrame;
            pnlPlayback.btnPrevFrame.Enabled = _animFrame > 0;

            pnlPlayback.btnLast.Enabled  = _animFrame != _maxFrame;
            pnlPlayback.btnFirst.Enabled = _animFrame > 1;

            if (_animFrame <= pnlPlayback.numFrameIndex.Maximum)
            {
                pnlPlayback.numFrameIndex.Value = _animFrame;
            }

            if (!_playing)
            {
                if (InterpolationEditor != null && InterpolationEditor.Visible)
                {
                    InterpolationEditor.Frame = CurrentFrame;
                }
                KeyframePanel.numFrame_ValueChanged();
            }
        }
Beispiel #4
0
        private static Matrix34 ProjectionTexMtx(SCN0CameraNode c, float frame)
        {
            CameraAnimationFrame f = c.GetAnimFrame(frame);

            if (c.ProjectionType == Wii.Graphics.ProjectionType.Orthographic)
            {
                return(LightMtxOrtho(
                           f.Height / 2.0f,
                           -f.Height / 2.0f,
                           -f.Height * f.Aspect / 2.0f,
                           f.Height * f.Aspect / 2.0f,
                           0.5f, -0.5f, 0.5f, 0.5f));
            }

            return(LightMtxPersp(
                       f.FovY, 1.0f,
                       0.5f, -0.5f, 0.5f, 0.5f));
        }
Beispiel #5
0
        /// <summary>
        /// This function returns a texture matrix
        /// that will aim the texture to the midpoint between the active camera
        /// and the given reference camera or light.
        /// </summary>
        public static Matrix EnvSpecMap(
            int refCam,
            int refLight,
            SCN0Node node,
            ModelPanelViewport v,
            float frame)
        {
            // Normal environmental map when neither the light nor the camera is specified.
            Matrix34 finalMtx = EnvironmentTexMtx();

            GLCamera cam = v.Camera;
            Vector3  vLook, camUp, camLook;
            Matrix   camMtx    = cam._matrixInverse;
            Matrix   invCamMtx = cam._matrix;

            Matrix34 m34 = (Matrix34)camMtx;

            camLook._x = -m34[8];
            camLook._y = -m34[9];
            camLook._z = -m34[10];

            if (refLight >= 0)
            {
                Vector3 lgtLook = GetLightLook(node, refLight, invCamMtx, v, frame, out bool specEnabled);

                // Specular light is already set as a vector taking the center position.
                if (!specEnabled)
                {
                    vLook = GetHalfAngle(camLook, lgtLook);
                }
                else
                {
                    vLook = -lgtLook;
                }

                if (Math.Abs(vLook._x) < 0.000001f &&
                    Math.Abs(vLook._z) < 0.000001f)
                {
                    camUp._x = camUp._y = 0.0f;
                    if (vLook._y <= 0.0f)
                    {
                        // Look straight down
                        camUp._z = -1.0f;
                    }
                    else
                    {
                        // Look straight up
                        camUp._z = 1.0f;
                    }
                }
                else
                {
                    camUp._x = camUp._z = 0.0f;
                    camUp._y = 1.0f;
                }
            }
            else if (refCam >= 0)
            {
                SCN0CameraNode camNode = null;

                if (node?.CameraGroup != null && refCam < node.CameraGroup.Children.Count)
                {
                    camNode = (SCN0CameraNode)node.CameraGroup.Children[refCam];
                }
                else
                {
                    camNode = new SCN0CameraNode();
                }

                camNode.GetModelViewMatrix(frame, out Matrix cM, out Matrix cMInv);

                // Map from the midpoint of the view camera and the specified camera.
                Matrix34 lgtCam = (Matrix34)cM;
                camUp._x = lgtCam[4];
                camUp._y = lgtCam[5];
                camUp._z = lgtCam[6];
                Vector3 lgtLook = new Vector3(-lgtCam[8], -lgtCam[9], -lgtCam[10]);

                vLook = GetHalfAngle(camLook, lgtLook);
            }
            else
            {
                return((Matrix)finalMtx);
            }

            vLook.Normalize();
            Vector3 vRight, vUp;

            vUp = (vRight = vLook.Cross(camUp).Normalize()).Cross(vLook);
            m34 = new Matrix34(
                vRight._x, vRight._y, vRight._z, 0.0f,
                vUp._x, vUp._y, vUp._z, 0.0f,
                vLook._x, vLook._y, vLook._z, 0.0f);

            m34     = (Matrix34)((Matrix)m34 * invCamMtx);
            m34[3]  = 0.0f;
            m34[7]  = 0.0f;
            m34[11] = 0.0f;

            return((Matrix)(finalMtx * m34));
        }
        public void RootChanged()
        {
            ResourceNode node = _targetNode;

            if (node is ISCN0KeyframeHolder)
            {
                if (node is SCN0LightNode)
                {
                    SCN0LightNode n = node as SCN0LightNode;

                    interpolationViewer.FrameLimit = n.FrameCount;
                    interpolationViewer.KeyRoot    = n.GetKeys(SelectedMode)._keyRoot;
                }
                else if (node is SCN0FogNode)
                {
                    SCN0FogNode n = node as SCN0FogNode;

                    interpolationViewer.FrameLimit = n.FrameCount;
                    interpolationViewer.KeyRoot    = n.GetKeys(SelectedMode)._keyRoot;
                }
                else if (node is SCN0CameraNode)
                {
                    SCN0CameraNode n = node as SCN0CameraNode;

                    interpolationViewer.FrameLimit = n.FrameCount;
                    interpolationViewer.KeyRoot    = n.GetKeys(SelectedMode)._keyRoot;
                }
            }
            else if (node is IKeyframeHolder)
            {
                if (node is CHR0EntryNode)
                {
                    CHR0EntryNode n = node as CHR0EntryNode;

                    interpolationViewer.FrameLimit = n._keyframes._frameCount;
                    interpolationViewer.KeyRoot    = n._keyframes._keyRoots[SelectedMode];
                }
                else if (node is SRT0TextureNode)
                {
                    SRT0TextureNode n = node as SRT0TextureNode;

                    interpolationViewer.FrameLimit = n._keyframes._frameCount;
                    int i = SelectedMode;
                    if (i == 2)
                    {
                        i = 3;
                    }
                    else if (i > 2)
                    {
                        i += 3;
                    }
                    interpolationViewer.KeyRoot = n._keyframes._keyRoots[i];
                }
            }
            else if (node is IKeyframeArrayHolder)
            {
                comboBox1.Enabled = false;

                if (node is SHP0VertexSetNode)
                {
                    SHP0VertexSetNode n = node as SHP0VertexSetNode;

                    interpolationViewer.FrameLimit = n._keyframes._frameLimit;
                    interpolationViewer.KeyRoot    = n._keyframes._keyRoot;
                }
            }
        }
Beispiel #7
0
        public void UpdateKeyframes()
        {
            listKeyframes.Items.Clear();
            bool t = _updating;

            _updating = true;
            if (_target is CHR0EntryNode || _target is SRT0TextureNode)
            {
                IKeyframeSource entry = _target as IKeyframeSource;
                if (entry.FrameCount > 0)
                {
                    if (_target is CHR0EntryNode)
                    {
                        CHRAnimationFrame a;
                        for (int x = 0; x < entry.FrameCount; x++)
                        {
                            if ((a = ((CHR0EntryNode)entry).GetAnimFrame(x)).HasKeys)
                            {
                                listKeyframes.Items.Add(a);
                            }
                        }
                    }
                    else if (_target is SRT0TextureNode)
                    {
                        SRTAnimationFrame a;
                        for (int x = 0; x < entry.FrameCount; x++)
                        {
                            if ((a = ((SRT0TextureNode)entry).GetAnimFrame(x)).HasKeys)
                            {
                                listKeyframes.Items.Add(a);
                            }
                        }
                    }
                }
            }
            else if (_target is SHP0VertexSetNode)
            {
                SHP0VertexSetNode e = _target as SHP0VertexSetNode;
                if (e.FrameCount > 0)
                {
                    for (KeyframeEntry entry = e.Keyframes._keyRoot._next; entry != e.Keyframes._keyRoot; entry = entry._next)
                    {
                        listKeyframes.Items.Add(new FloatKeyframe(entry));
                    }
                }
            }
            else if (_target is SCN0EntryNode)
            {
                if (_target is SCN0CameraNode)
                {
                    CameraAnimationFrame a;
                    SCN0CameraNode       entry = _target as SCN0CameraNode;
                    if (entry.FrameCount > 0)
                    {
                        for (int x = 0; x < entry.FrameCount; x++)
                        {
                            if ((a = entry.GetAnimFrame(x)).HasKeys)
                            {
                                listKeyframes.Items.Add(a);
                            }
                        }
                    }
                }
                else if (_target is SCN0LightNode)
                {
                    LightAnimationFrame a;
                    SCN0LightNode       entry = _target as SCN0LightNode;
                    if (entry.FrameCount > 0)
                    {
                        for (int x = 0; x < entry.FrameCount; x++)
                        {
                            if ((a = entry.GetAnimFrame(x)).HasKeys)
                            {
                                listKeyframes.Items.Add(a);
                            }
                        }
                    }
                }
                else if (_target is SCN0FogNode)
                {
                    FogAnimationFrame a;
                    SCN0FogNode       entry = _target as SCN0FogNode;
                    if (entry.FrameCount > 0)
                    {
                        for (int x = 0; x < entry.FrameCount; x++)
                        {
                            if ((a = entry.GetAnimFrame(x)).HasKeys)
                            {
                                listKeyframes.Items.Add(a);
                            }
                        }
                    }
                }
            }
            _updating = t;
        }
Beispiel #8
0
        public void UpdateKeyframe(int x)
        {
            if (!Visible)
            {
                return;
            }

            _updating = true;
            if (_target is CHR0EntryNode || _target is SRT0TextureNode)
            {
                IKeyframeSource entry = _target as IKeyframeSource;
                for (int w = 0; w < listKeyframes.Items.Count; w++)
                {
                    if (_target is CHR0EntryNode)
                    {
                        CHRAnimationFrame a = (CHRAnimationFrame)listKeyframes.Items[w];
                        if (a.Index == x)
                        {
                            CHRAnimationFrame r = ((CHR0EntryNode)entry).GetAnimFrame(x);

                            if (r.HasKeys)
                            {
                                listKeyframes.Items[w] = r;
                            }
                            else
                            {
                                listKeyframes.Items.RemoveAt(w);
                            }

                            _updating = false;
                            return;
                        }
                    }
                    else if (_target is SRT0TextureNode)
                    {
                        SRTAnimationFrame a = (SRTAnimationFrame)listKeyframes.Items[w];
                        if (a.Index == x)
                        {
                            SRTAnimationFrame r = ((SRT0TextureNode)entry).GetAnimFrame(x);

                            if (r.HasKeys)
                            {
                                listKeyframes.Items[w] = r;
                            }
                            else
                            {
                                listKeyframes.Items.RemoveAt(w);
                            }

                            _updating = false;
                            return;
                        }
                    }
                }

                UpdateKeyframes();
            }
            else if (_target is SHP0VertexSetNode)
            {
                SHP0VertexSetNode entry = _target as SHP0VertexSetNode;
                int w = 0;
                foreach (FloatKeyframe a in listKeyframes.Items)
                {
                    if (a.Index == x)
                    {
                        KeyframeEntry e = entry.GetKeyframe(x);

                        if (e != null)
                        {
                            listKeyframes.Items[w] = new FloatKeyframe(e);
                        }
                        else
                        {
                            listKeyframes.Items.RemoveAt(w);
                        }

                        _updating = false;
                        return;
                    }
                    w++;
                }

                UpdateKeyframes();
            }
            else if (_target is SCN0EntryNode)
            {
                if (_target is SCN0CameraNode)
                {
                    SCN0CameraNode entry = _target as SCN0CameraNode;
                    for (int w = 0; w < listKeyframes.Items.Count; w++)
                    {
                        CameraAnimationFrame a = (CameraAnimationFrame)listKeyframes.Items[w];
                        if (a.Index == x)
                        {
                            CameraAnimationFrame r = entry.GetAnimFrame(x);

                            if (r.HasKeys)
                            {
                                listKeyframes.Items[w] = r;
                            }
                            else
                            {
                                listKeyframes.Items.RemoveAt(w);
                            }

                            _updating = false;
                            return;
                        }
                    }

                    UpdateKeyframes();
                }
                else if (_target is SCN0LightNode)
                {
                    SCN0LightNode entry = _target as SCN0LightNode;
                    for (int w = 0; w < listKeyframes.Items.Count; w++)
                    {
                        LightAnimationFrame a = (LightAnimationFrame)listKeyframes.Items[w];
                        if (a.Index == x)
                        {
                            LightAnimationFrame r = entry.GetAnimFrame(x);

                            if (r.HasKeys)
                            {
                                listKeyframes.Items[w] = r;
                            }
                            else
                            {
                                listKeyframes.Items.RemoveAt(w);
                            }

                            _updating = false;
                            return;
                        }
                    }

                    UpdateKeyframes();
                }
                else if (_target is SCN0FogNode)
                {
                    SCN0FogNode entry = _target as SCN0FogNode;
                    for (int w = 0; w < listKeyframes.Items.Count; w++)
                    {
                        FogAnimationFrame a = (FogAnimationFrame)listKeyframes.Items[w];
                        if (a.Index == x)
                        {
                            FogAnimationFrame r = entry.GetAnimFrame(x);

                            if (r.HasKeys)
                            {
                                listKeyframes.Items[w] = r;
                            }
                            else
                            {
                                listKeyframes.Items.RemoveAt(w);
                            }

                            _updating = false;
                            return;
                        }
                    }

                    UpdateKeyframes();
                }
            }
            _updating = false;
        }
Beispiel #9
0
        public unsafe void RenderSCN0Controls(TKContext context)
        {
            if (_scn0 == null)
            {
                return;
            }

            GL.Color4(Color.Blue);
            GL.Disable(EnableCap.Lighting);

            if (scn0Editor._light != null)
            {
                SCN0LightNode l     = scn0Editor._light;
                Vector3       start = new Vector3(
                    l.GetFrameValue(LightKeyframeMode.StartX, CurrentFrame - 1),
                    l.GetFrameValue(LightKeyframeMode.StartY, CurrentFrame - 1),
                    l.GetFrameValue(LightKeyframeMode.StartZ, CurrentFrame - 1));
                Vector3 end = new Vector3(
                    l.GetFrameValue(LightKeyframeMode.EndX, CurrentFrame - 1),
                    l.GetFrameValue(LightKeyframeMode.EndY, CurrentFrame - 1),
                    l.GetFrameValue(LightKeyframeMode.EndZ, CurrentFrame - 1));

                //GL.Color4(Color.Coral);
                GL.Begin(BeginMode.Lines);

                GL.Vertex3(start._x, start._y, start._z);
                GL.Vertex3(end._x, end._y, end._z);

                GL.End();

                //GL.Color4(Color.MediumPurple);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(l.GetFrameValue(LightKeyframeMode.StartX, i), l.GetFrameValue(LightKeyframeMode.StartY, i), l.GetFrameValue(LightKeyframeMode.StartZ, i));
                //GL.End();

                //GL.Color4(Color.ForestGreen);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(l.GetFrameValue(LightKeyframeMode.EndX, i), l.GetFrameValue(LightKeyframeMode.EndY, i), l.GetFrameValue(LightKeyframeMode.EndZ, i));
                //GL.End();

                ModelPanel.ScreenText["Light Start"] = ModelPanel.Project(start);
                ModelPanel.ScreenText["Light End"]   = ModelPanel.Project(end);

                //Render these if selected
                //if (_lightStartSelected || _lightEndSelected)
                //{
                //    Matrix m;
                //    float s1 = start.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    float e1 = end.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    GLDisplayList axis = GetAxes();
                //    if (_lightStartSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(s1), new Vector3(), start);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //    if (_lightEndSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(e1), new Vector3(), end);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //}
            }

            if (scn0Editor._camera != null)
            {
                SCN0CameraNode c     = scn0Editor._camera;
                Vector3        start = new Vector3(
                    c.GetFrameValue(CameraKeyframeMode.PosX, CurrentFrame - 1),
                    c.GetFrameValue(CameraKeyframeMode.PosY, CurrentFrame - 1),
                    c.GetFrameValue(CameraKeyframeMode.PosZ, CurrentFrame - 1));
                Vector3 end = new Vector3(
                    c.GetFrameValue(CameraKeyframeMode.AimX, CurrentFrame - 1),
                    c.GetFrameValue(CameraKeyframeMode.AimY, CurrentFrame - 1),
                    c.GetFrameValue(CameraKeyframeMode.AimZ, CurrentFrame - 1));

                //GL.Color4(Color.Blue);
                GL.Begin(BeginMode.Lines);

                GL.Vertex3(start._x, start._y, start._z);
                GL.Vertex3(end._x, end._y, end._z);

                GL.End();

                //GL.Color4(Color.OrangeRed);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(c.GetFrameValue(CameraKeyframeMode.PosX, i), c.GetFrameValue(CameraKeyframeMode.PosY, i), c.GetFrameValue(CameraKeyframeMode.PosZ, i));
                //GL.End();

                //GL.Color4(Color.SkyBlue);
                //GL.Begin(BeginMode.LineStrip);
                //for (int i = 0; i < MaxFrame; i++)
                //    GL.Vertex3(c.GetFrameValue(CameraKeyframeMode.AimX, i), c.GetFrameValue(CameraKeyframeMode.AimY, i), c.GetFrameValue(CameraKeyframeMode.AimZ, i));
                //GL.End();

                ModelPanel.ScreenText["Camera Position"] = ModelPanel.Project(start);
                ModelPanel.ScreenText["Camera Aim"]      = ModelPanel.Project(end);

                GL.Color4(Color.Black);

                //Render these if selected
                //if (_lightStartSelected || _lightEndSelected)
                //{
                //    Matrix m;
                //    float s = start.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    float e = end.TrueDistance(CamLoc) / _orbRadius * 0.1f;
                //    GLDisplayList axis = GetAxes();
                //    if (_lightStartSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(s), new Vector3(), start);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //    if (_lightEndSelected)
                //    {
                //        m = Matrix.TransformMatrix(new Vector3(e), new Vector3(), end);

                //        GL.PushMatrix();
                //        GL.MultMatrix((float*)&m);

                //        axis.Call();
                //        GL.PopMatrix();
                //    }
                //}
            }
        }