Example #1
0
        public void LoadGraph(string file)
        {
            FileStream   fs = new FileStream(file, FileMode.Open, FileAccess.Read);
            BinaryReader r  = new BinaryReader(fs);

            Help.IOHelp.r = r;
            int cc = r.ReadInt32();

            for (int i = 0; i < cc; i++)
            {
                Cam3D nc = new Cam3D();
                nc.Read( );
                Cams.Add(nc);
            }
            int lc = r.ReadInt32();

            for (int i = 0; i < lc; i++)
            {
                Light3D nl = new FusionEngine.Lighting.Light3D();
                nl.Read( );
                Lights.Add(nl);
            }
            Entity3D re = new Entity3D();

            Root = re;
            re.Read( );
            fs.Close( );
        }
Example #2
0
        public virtual void RenderNodeNoLights(Node3D node)
        {
            if (CamOverride != null)
            {
                foreach (Light3D l in Lights)
                {
                    Light3D.Active = l;

                    node.Present(CamOverride);
                }
            }
            else
            {
                foreach (Cam3D c in Cams)
                {
                    GL.Disable(EnableCap.Blend);

                    // Console.WriteLine("Presenting:" + node.Name);
                    node.Present(c);

                    // foreach (var n in Nodes) { n.Present(c); }
                }
            }
            foreach (Node3D snode in node.Sub)
            {
                // Console.WriteLine("Rendering Node:" + snode.Name);
                RenderNodeNoLights(snode);
            }
        }
Example #3
0
 public void BeginFrameNode(Node3D node)
 {
     node.StartFrame( );
     foreach (Node3D snode in node.Sub)
     {
         BeginFrameNode(snode);
     }
 }
Example #4
0
 public virtual void UpdateNode(Node3D node)
 {
     node.Update( );
     foreach (Node3D snode in node.Sub)
     {
         UpdateNode(snode);
     }
 }
Example #5
0
 public void RestoreNode(Node3D node)
 {
     node.RestoreProps( );
     foreach (Node3D nn in node.Sub)
     {
         RestoreNode(nn);
     }
 }
Example #6
0
 public void CopyNode(Node3D node)
 {
     node.CopyProps( );
     foreach (Node3D nn in node.Sub)
     {
         CopyNode(nn);
     }
 }
Example #7
0
 public virtual void RenderNode(Node3D node)
 {
     // Console.WriteLine("RenderNode:" + node.Name);
     RenderThis(node);
     foreach (Node3D snode in node.Sub)
     {
         // Console.WriteLine("Rendering Node:" + snode.Name);
         RenderNode(snode);
     }
 }
Example #8
0
 public virtual void RenderNodeDepth(Node3D node, Cam3D c)
 {
     if (node.CastDepth)
     {
         node.PresentDepth(c);
     }
     foreach (Node3D snode in node.Sub)
     {
         RenderNodeDepth(snode, c);
     }
 }
Example #9
0
 private void NodeToList(Node3D node, bool meshes, List <Node3D> list)
 {
     if (meshes)
     {
         if (node is Entity3D)
         {
             list.Add(node);
         }
     }
     else
     {
         list.Add(node);
     }
     foreach (Node3D n2 in node.Sub)
     {
         NodeToList(n2, meshes, list);
     }
 }
Example #10
0
        public virtual void RenderNodeByTags(List <string> tags, Node3D node)
        {
            bool rt = false;

            foreach (string tag in tags)
            {
                if (node.RenderTags.Contains(tag))
                {
                    rt = true;
                    RenderThis(node);
                    break;
                }
            }
            if (rt)
            {
                foreach (Node3D n in node.Sub)
                {
                    RenderNodeByTags(tags, n);
                }
            }
        }
Example #11
0
        public FusionEngine.Pick.PickResult CamPick(int x, int y)
        {
            Pick.PickResult res = new Pick.PickResult( );

            List <Node3D> nl = GetList(true);

            Pick.Ray mr = Pick.Picker.CamRay(Cams [0], x, y);

            float  cd = 0;
            bool   firstHit = true;
            float  cu = 0, cv = 0;
            Node3D cn = null;

            foreach (Node3D n in nl)
            {
                Entity3D e = n as Entity3D;

                foreach (Data.Mesh3D msh in e.Meshes)
                {
                    for (int i = 0; i < msh.TriData.Length; i++)
                    {
                        int     v0 = msh.TriData[i].V0;
                        int     v1 = msh.TriData[i].V1;
                        int     v2 = msh.TriData[i].v2;
                        Vector3 r0, r1, r2;
                        r0 = Rot(msh.VertexData [v0].Pos, n);
                        r1 = Rot(msh.VertexData [v1].Pos, n);
                        r2 = Rot(msh.VertexData [v2].Pos, n);
                        Vector3?pr = Pick.Picker.GetTimeAndUvCoord(mr.pos, mr.dir, r0, r1, r2);
                        if (pr == null)
                        {
                        }
                        else
                        {
                            Vector3 cr = (Vector3)pr;
                            if (cr.X < cd || firstHit)
                            {
                                firstHit = false;
                                cd       = cr.X;
                                cn       = n;
                                cu       = cr.Y;
                                cv       = cr.Z;
                            }
                        }
                    }
                }
            }

            if (firstHit)
            {
                return(null);
            }

            res.Dist = cd;
            res.Node = cn;
            res.Pos  = Pick.Picker.GetTrilinearCoordinateOfTheHit(cd, mr.pos, mr.dir);
            res.Ray  = mr;
            res.UV   = new Vector3(cu, cv, 0);

            return(res);
        }
Example #12
0
 public Vector3 Rot(Vector3 p, Node3D n)
 {
     return(Vector3.TransformPosition(p, n.World));
 }
Example #13
0
 public virtual void Add(Node3D n)
 {
     Root.Add(n);
     n.Top = Root;
 }
Example #14
0
        private void RenderThis(Node3D node)
        {
            if (node.Name == "Terrain")
            {
            }
            if (CamOverride != null)
            {
                foreach (Light3D l in Lights)
                {
                    Light3D.Active = l;

                    node.Present(CamOverride);
                }
            }
            else
            {
                foreach (Cam3D c in Cams)
                {
                    if (node.AlwaysAlpha)
                    {
                        Entity3D ge = node as Entity3D;
                        if (ge.Renderer is Visuals.RMultiPass)
                        {
                            ge.Renderer = new Visuals.VRNoFx( );
                        }
                        GL.Enable(EnableCap.Blend);
                        GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
                        node.Present(c);
                        continue;
                    }
                    if (node.Lit)
                    {
                        bool first = true;
                        foreach (Light3D l in Lights)
                        {
                            Light3D.Active = l;

                            if (first)
                            {
                                first = false;
                                GL.Disable(EnableCap.Blend);
                            }
                            else
                            {
                                GL.Enable(EnableCap.Blend);
                                GL.BlendFunc(BlendingFactor.One, BlendingFactor.One);
                            }
                            // Console.WriteLine("Presenting:" + node.Name);
                            if (node.Name.Contains("Merged"))
                            {
                            }
                            node.Present(c);

                            // foreach (var n in Nodes) { n.Present(c); }
                        }
                    }
                    else
                    {
                        if (node.FaceCamera)
                        {
                            node.LookAt(c.LocalPos, new Vector3(0, 1, 0));
                        }
                        GL.Enable(EnableCap.Blend);
                        GL.BlendFunc(BlendingFactor.Src1Alpha, BlendingFactor.OneMinusSrcAlpha);
                        GL.DepthMask(false);
                        node.Present(c);
                        GL.DepthMask(true);
                    }
                }
            }
        }