public void Write( ) { Help.IOHelp.WriteInt(Scripts.Count); foreach (Script.ScriptLink s in Scripts) { Help.IOHelp.WriteString(s.Name); Help.IOHelp.WriteString(s.FilePath); } Help.IOHelp.WriteMatrix(LocalTurn); Help.IOHelp.WriteVec(LocalPos); Help.IOHelp.WriteVec(LocalScale); Help.IOHelp.WriteString(Name); Help.IOHelp.WriteBool(AlwaysAlpha); Help.IOHelp.WriteBool(On); Help.IOHelp.WriteInt(Sub.Count); int mc = Meshes.Count; Help.IOHelp.WriteInt(mc); foreach (Mesh3D msh in Meshes) { msh.Write( ); } foreach (Node3D sn in Sub) { Entity3D e = sn as Entity3D; e.Write( ); } }
public void SaveGraph(string file) { FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); Help.IOHelp.w = bw; bw.Write(Cams.Count); foreach (Cam3D c in Cams) { c.Write( ); } bw.Write(Lights.Count); foreach (Light3D c in Lights) { c.Write( ); } Entity3D r = Root as Entity3D; if (Root != null) { r.Write( ); } fs.Flush( ); fs.Close( ); }
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( ); }
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); } }
public void SetMat(Material3D mat) { foreach (Mesh3D m in Meshes) { m.Mat = mat; } foreach (Node3D n in Sub) { if (n is Entity3D || n is Terrain.Terrain3D) { ; } { Entity3D ge = n as Entity3D; ge.SetMat(mat); } } }
public void GetVerts(List <Vector3> verts, Entity3D node) { foreach (Mesh3D m in node.Meshes) { for (int i = 0; i < m.NumVertices; i++) { int vid = i * 3; Vector3 nv = 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); } }
public void GetBounds(Entity3D node) { foreach (Mesh3D m in node.Meshes) { for (int i = 0; i < m.NumVertices; i++) { int vid = i * 3; if (m.Vertices [vid] < sw) { sw = m.Vertices [vid]; } if (m.Vertices [vid] > bw) { bw = m.Vertices [vid]; } if (m.Vertices [vid + 1] < sh) { sh = m.Vertices [vid + 1]; } if (m.Vertices [vid + 1] > bh) { bh = m.Vertices [vid + 1]; } if (m.Vertices [vid + 2] < sd) { sd = m.Vertices [vid + 2]; } if (m.Vertices [vid + 2] > bd) { bd = m.Vertices [vid + 2]; } } } foreach (Node3D snode in node.Sub) { if (snode is Entity3D || snode is Terrain.Terrain3D) { GetBounds(snode as Entity3D); } } }
public void Read( ) { int ns1 = Help.IOHelp.ReadInt(); for (int i = 0; i < ns1; i++) { Script.ScriptLink sb = new Script.ScriptLink { Name = Help.IOHelp.ReadString( ), FilePath = Help.IOHelp.ReadString( ) }; Scripts.Add(sb); } LocalTurn = Help.IOHelp.ReadMatrix( ); LocalPos = Help.IOHelp.ReadVec3( ); LocalScale = Help.IOHelp.ReadVec3( ); Name = Help.IOHelp.ReadString( ); AlwaysAlpha = Help.IOHelp.ReadBool( ); On = Help.IOHelp.ReadBool( ); int ns = Help.IOHelp.ReadInt(); int mc = Help.IOHelp.ReadInt(); for (int m = 0; m < mc; m++) { Mesh3D msh = new Mesh3D(); msh.Read( ); Meshes.Add(msh); } for (int i = 0; i < ns; i++) { Entity3D gn = new Entity3D(); Sub.Add(gn); gn.Top = this; gn.Read( ); } SetMultiPass( ); }
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); }
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); } } } }