コード例 #1
0
ファイル: Matrix34.cs プロジェクト: libertyernie/BrawlCrate
        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);
        }
コード例 #2
0
        public void NewScn()
        {
            SCN0Node    node = ((BRRESNode)_resource).CreateResource <SCN0Node>("NewSCN");
            BaseWrapper res  = this.FindResource(node, true);

            res = res.FindResource(node, false);
            res.EnsureVisible();
            res.TreeView.SelectedNode = res;
        }
コード例 #3
0
ファイル: Matrix34.cs プロジェクト: libertyernie/BrawlCrate
        private static unsafe Vector3 GetLightLook(
            SCN0Node node, int refLight, Matrix invCamMtx, ModelPanelViewport v, float frame, out bool specEnabled)
        {
            Vector3   start, end;
            LightType lightType;

            if (node?.LightGroup != null && refLight < node.LightGroup.Children.Count && refLight >= 0)
            {
                //SCN0 light exists
                SCN0LightNode lightNode = (SCN0LightNode)node.LightGroup.Children[refLight];
                start       = lightNode.GetStart(frame);
                end         = lightNode.GetEnd(frame);
                lightType   = lightNode.LightType;
                specEnabled = lightNode.SpecularEnabled;
            }
            else //Use the model viewer light settings by default
            {
                start       = (Vector3)v._posLight;
                end         = new Vector3();
                lightType   = LightType.Directional;
                specEnabled = true;
            }

            //Don't use if not enabled?
            //bool enabled = lightNode.GetEnabled(frame);

            Vector3 lgtLook = (end - start).Normalize();

            bool temp = lgtLook._x == 0.0f && lgtLook._y == 0.0f && lgtLook._z == 0.0f;

            if (lightType != LightType.Spotlight && !specEnabled || temp)
            {
                // Use light position if they are diffuse light or if light has no direction.
                if (temp)
                {
                    lgtLook = start;
                }

                lgtLook = -(invCamMtx.GetRotationMatrix() * lgtLook);
                if (lgtLook._x == 0.0f &&
                    lgtLook._y == 0.0f &&
                    lgtLook._z == 0.0f)
                {
                    // If the light position is the origin, treat as if light is coming from the top of y-axis.
                    lgtLook._y = -1.0f;
                }
            }
            else
            {
                lgtLook = invCamMtx.GetRotationMatrix() * lgtLook;
            }

            return(lgtLook);
        }
コード例 #4
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            SCN0Node     node = (context.Instance as SCN0EntryNode).Parent.Parent as SCN0Node;
            ResourceNode n    = node.FindChild("Lights(NW4R)", false);

            if (n != null)
            {
                return(new StandardValuesCollection(n.Children.Select(r => r.ToString()).ToList()));
            }

            return(null);
        }
コード例 #5
0
        public void ImportScn()
        {
            if (Program.OpenFile(FileFilters.SCN0, out string path) > 0)
            {
                SCN0Node node = NodeFactory.FromFile(null, path) as SCN0Node;
                ((BRRESNode)_resource).GetOrCreateFolder <SCN0Node>().AddChild(node);

                BaseWrapper w = FindResource(node, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
        }
コード例 #6
0
ファイル: Matrix34.cs プロジェクト: libertyernie/BrawlCrate
        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());
        }
コード例 #7
0
        public void replaceKeepCamera()
        {
            if (Program.OpenFile(ReplaceFilter, out string inPath))
            {
                using (SCN0Node ext = NodeFactory.FromFile(null, inPath, typeof(SCN0Node)) as SCN0Node)
                {
                    if (ext == null)
                    {
                        MessageBox.Show("The selected SCN0 file could not be read.");
                        return;
                    }
                    ext.Populate();
                    ext.CameraGroup.Children.Clear();
                    foreach (ResourceNode n in ((SCN0Node)Resource).CameraGroup.Children)
                    {
                        ext.CameraGroup.AddChild(n);
                    }

                    string s = Path.GetTempFileName() + ".scn0";
                    ext.Export(s);
                    Resource.Replace(s);
                }
            }
        }
コード例 #8
0
ファイル: Matrix34.cs プロジェクト: libertyernie/BrawlCrate
        /// <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));
        }
コード例 #9
0
ファイル: Matrix34.cs プロジェクト: libertyernie/BrawlCrate
        public static Matrix EnvLightMap(int refLight, SCN0Node node, ModelPanelViewport v, float frame)
        {
            Matrix   m         = Matrix.Identity;
            GLCamera cam       = v.Camera;
            Matrix   camMtx    = cam._matrix;
            Matrix   invCamMtx = cam._matrixInverse;

            Matrix34 envMtx = new Matrix34(
                0.5f, 0.0f, 0.0f, 0.5f,
                0.0f, -0.5f, 0.0f, 0.5f,
                0.0f, 0.0f, 0.0f, 1.0f);

            //If no light is referenced, use the BrawlCrate built-in light
            if (refLight < 0 || node?.LightGroup != null && refLight >= node.LightGroup.Children.Count)
            {
                refLight = 0;
                node     = null;
            }

            // The light position and direction needs to be transformed with the camera's inverse matrix.
            Vector3 vLook, camUp, vRight, vUp;

            vLook = GetLightLook(node, refLight, invCamMtx, v, frame, out bool specEnabled).Normalize();

            // Calculate without using a target because the margin of error for calculations must be taken into account when the light is far away.
            // Take the absolute value as a measure against transformation margin.
            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;
            }

            vUp = (vRight = vLook.Cross(camUp).Normalize()).Cross(vLook);

            Matrix34 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)(envMtx * m34));

            //return (Matrix)envMtx * Matrix.RotationMatrix(new Vector3().LookatAngles((Vector3)v._posLight) * Maths._rad2degf);
        }
コード例 #10
0
 public unsafe void SetSCN0(SCN0Node node)
 {
     if (_matList != null)
         foreach (MDL0MaterialNode mat in _matList)
             mat.SetSCN0(node);
 }
コード例 #11
0
 internal unsafe void SetSCN0(SCN0Node node)
 {
     if (node == null)
     {
         _lightSet = null;
         _fog = null;
     }
     else
     {
         SCN0GroupNode g = node.GetFolder<SCN0LightSetNode>();
         _lightSet = LightSetIndex < g.Children.Count && LightSetIndex >= 0 ? g.Children[LightSetIndex] as SCN0LightSetNode : null;
         g = node.GetFolder<SCN0FogNode>();
         _fog = FogIndex < g.Children.Count && FogIndex >= 0 ? g.Children[FogIndex] as SCN0FogNode : null;
     }
 }