Beispiel #1
0
        public Node3D ReadNode()
        {
            int    node_t = Help.IOHelp.ReadInt();
            Node3D nn     = null;

            if (node_t == 1)
            {
                Entity3D new_e = new Entity3D();
                new_e.Read();
                nn = new_e;
            }
            else if (node_t == 0)
            {
                Node3D new_n = new Node3D();
                new_n.Read();
                nn = new_n;
            }
            else
            {
                System.Environment.Exit(-3);
            }
            int sc = Help.IOHelp.ReadInt();

            for (int i = 0; i < sc; i++)
            {
                var rn = ReadNode();
                rn.Top = nn;
                nn.Sub.Add(rn);
            }
            return(nn);
        }
Beispiel #2
0
        public static Node3D LoadNode(string path)
        {
            FileStream   fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            BinaryReader r  = new BinaryReader(fs);

            Help.IOHelp.r = r;

            int et = IOHelp.ReadInt();

            switch (et)
            {
            case 1:
                var new_ent = new Entity3D();
                new_ent.Read();
                fs.Close();
                return(new_ent);

                break;

            case 2:
                var new_node = new Node3D();
                new_node.Read();
                fs.Close();
                return(new_node);

                break;
            }

            fs.Close();
            return(null);
        }
Beispiel #3
0
        public Entity3D Clone()
        {
            var new_ent = new Entity3D();

            new_ent.Meshes   = Meshes;
            new_ent.Renderer = Renderer;
            return(new_ent);
        }
Beispiel #4
0
        public List <Vector3> GetAllVerts()
        {
            Entity3D       node = this;
            List <Vector3> nl   = new List <Vector3>();

            GetVerts(nl, this);
            return(nl);
        }
Beispiel #5
0
 private void DScale(float x, float y, float z, Entity3D node)
 {
     foreach (Mesh3D m in node.Meshes)
     {
         m.Scale(x, y, z);
     }
     foreach (Node3D snode in node.Sub)
     {
         DScale(x, y, z, snode as Entity3D);
     }
 }
Beispiel #6
0
        public virtual void RenderEntity(Entity3D ent)
        {
            LastCam = Cams[0];

            SubGraph?.Render();
            List <string> defTags = new List <string>
            {
                "All"
            };

            RenderNodeByTags(defTags, ent);
        }
Beispiel #7
0
 public void GetTris(List <int> tris, Entity3D node)
 {
     foreach (Mesh3D m in Meshes)
     {
         for (int i = 0; i < m.TriData.Length; i++)
         {
             tris.Add(m.TriData[i].V0);
             tris.Add(m.TriData[i].V1);
             tris.Add(m.TriData[i].v2);
         }
     }
     foreach (var s_node in Sub)
     {
         GetTris(tris, (Entity3D)s_node);
     }
 }
Beispiel #8
0
        public void GetBounds(Entity3D node)
        {
            foreach (Mesh3D m in node.Meshes)
            {
                if (m.VertexData == null)
                {
                    return;
                }
                for (int i = 0; i < m.VertexData.Length; i++)
                {
                    var vr = m.VertexData[i].Pos;

                    int vid = i * 3;
                    if (vr.X < sw)
                    {
                        sw = vr.X;
                    }
                    if (vr.X > bw)
                    {
                        bw = vr.X;
                    }
                    if (vr.Y < sh)
                    {
                        sh = vr.Y;
                    }
                    if (vr.Y > bh)
                    {
                        bh = vr.Y;
                    }
                    if (vr.Z < sd)
                    {
                        sd = vr.Z;
                    }
                    if (vr.Z > bd)
                    {
                        bd = vr.Z;
                    }
                }
            }
            foreach (Node3D snode in node.Sub)
            {
                if (snode is Entity3D || snode is Terrain.Terrain3D)
                {
                    GetBounds(snode as Entity3D);
                }
            }
        }
Beispiel #9
0
        public void SetMat(Material3D mat)
        {
            foreach (Mesh3D m in Meshes)
            {
                m.Material = mat;
            }
            foreach (Node3D n in Sub)
            {
                if (n is Entity3D || n is Terrain.Terrain3D)
                {
                    ;
                }

                {
                    Entity3D ge = n as Entity3D;
                    ge.SetMat(mat);
                }
            }
        }
Beispiel #10
0
        public void GetVerts(List <Vector3> verts, Entity3D node)
        {
            foreach (Mesh3D m in node.Meshes)
            {
                for (int i = 0; i < m.VertexData.Length; i++)
                {
                    //int vid = i * 3;

                    Vector3 nv = m.VertexData[i].Pos;// new Vector3(m.Vertices[vid], m.Vertices[vid + 1], m.Vertices[vid + 2]);
                    nv = Vector3.TransformPosition(nv, node.World);
                    verts.Add(nv);
                    // verts.Add(m.Vertices[vid]); verts.Add(m.Vertices[vid + 1]);
                    // verts.Add(m.Vertices[vid + 2]);
                }
            }
            foreach (Node3D snode in node.Sub)
            {
                GetVerts(verts, snode as Entity3D);
            }
        }
Beispiel #11
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 second = true;
                        bool first  = true;

                        foreach (Light3D l in Lights)
                        {
                            Light3D.Active = l;

                            if (first)
                            {
                                first = false;
                                GL.Disable(EnableCap.Blend);
                            }
                            else if (second)
                            {
                                second = false;
                                GL.Enable(EnableCap.Blend);
                                GL.BlendFunc(BlendingFactor.One, BlendingFactor.One);
                            }

                            node.Present(c);

                            // foreach (var n in Nodes) { n.Present(c); }
                        }
                        GL.Disable(EnableCap.Blend);
                    }
                    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);
                    }
                }
            }
        }
Beispiel #12
0
        public void InitThreads()

        {
            void CheckThread()
            {
                if (SceneTransforms == null)
                {
                    SceneTransforms = new Thread[MaxThreads];
                }
                while (true)
                {
                    if (SceneUpdating)
                    {
                        int dc = 0;

                        foreach (var th in SceneInfos)
                        {
                            if (th.Done)
                            {
                                dc++;
                            }
                        }
                        if (dc == SceneInfos.Length)
                        {
                            SceneUpdating = false;
                        }
                    }
                    if (SceneChanged && SceneUpdating == false)
                    {
                        SceneUpdating = true;
                        SceneChanged  = false;
                        foreach (var thr in SceneTransforms)
                        {
                            if (thr == null)
                            {
                                continue;
                            }
                            if (thr.ThreadState == ThreadState.Running)
                            {
                                thr.Abort();
                            }
                        }

                        List <Node3D> node_list = this.GetList(true);
                        int           vc        = 0;
                        int           bc        = 0;
                        foreach (var n in node_list)
                        {
                            var ent = n as Entity3D;

                            foreach (var m in ent.Meshes)
                            {
                                vc = vc + m.TriData.Length * 3;
                                bc = bc + m.TriData.Length * 3;
                            }
                        }
                        SceneCache = new Vector3[vc];
                        SceneNodes = new Entity3D[vc];

                        SceneInfos = new SceneIntristics[MaxThreads];

                        int pnc = node_list.Count / MaxThreads;

                        int cnc = 0;
                        int tid = 0;
                        for (int i = 0; i < MaxThreads; i++)
                        {
                            SceneInfos[i]      = new SceneIntristics();
                            SceneInfos[i].Done = true;
                        }
                        bool first = true;
                        int  vv    = 0;
                        foreach (var nl in node_list)
                        {
                            if (first)
                            {
                                first = false;
                                SceneInfos[tid].Begin = vv;
                                SceneInfos[tid].Done  = false;
                            }
                            SceneInfos[tid].Ents.Add(nl as Entity3D);
                            Entity3D me = nl as Entity3D;
                            foreach (var msh in me.Meshes)
                            {
                                vv = vv + msh.TriData.Length * 3;
                            }

                            cnc++;
                            if (cnc >= pnc)
                            {
                                SceneInfos[tid].End = vv;
                                cnc = 0;
                                tid++;
                                first = true;
                            }
                        }
                        SceneLut.Clear();
                        tid = 0;
                        foreach (var info in SceneInfos)
                        {
                            if (info.Ents.Count > 0)
                            {
                                void procScene(object obj)
                                {
                                    SceneIntristics si = obj as SceneIntristics;
                                    int             id = si.ThreadID;
                                    int             sv = si.Begin;

                                    System.Console.WriteLine("Begin:" + si.Begin + " End:" + si.End);
                                    foreach (var node in si.Ents)
                                    {
                                        System.Console.WriteLine("Node:" + node.Name);
                                        Matrix4 n_m = node.World;
                                        foreach (var msh in node.Meshes)
                                        {
                                            System.Console.WriteLine("Mesh:" + msh.TriData.Length);

                                            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, node);
                                                r1                 = Rot(msh.VertexData[v1].Pos, node);
                                                r2                 = Rot(msh.VertexData[v2].Pos, node);
                                                SceneNodes[sv]     = node;
                                                SceneNodes[sv + 1] = node;
                                                SceneNodes[sv + 2] = node;
                                                SceneCache[sv++]   = r0;
                                                SceneCache[sv++]   = r1;
                                                SceneCache[sv++]   = r2;
                                            }
                                        }
                                    }
                                    si.Done = true;
                                    System.Console.WriteLine("SceneThread:" + id + " complete.");
                                }

                                info.ThreadID = tid;
                                info.Thr      = new Thread(new ParameterizedThreadStart(procScene));
                                info.Thr.Start(info);
                            }
                            tid++;
                        }

                        System.Console.WriteLine("Checked:" + node_list.Count + " nodes");
                        //SceneChanged = false;
                    }
                    Thread.Sleep(5);
                }
            }

            SceneCheck = new Thread(new ThreadStart(CheckThread));
            SceneCheck.Start();
        }