Beispiel #1
0
 public void inputKey(KeyPressEventArgs e)
 {
     if (e.KeyChar == 's')
     {
         if (Snack.getdirc() != face.down)
         {
             input = face.up;
         }
     }
     else if (e.KeyChar == 'd')
     {
         if (Snack.getdirc() != face.left)
         {
             input = face.right;
         }
     }
     else if (e.KeyChar == 'a')
     {
         if (Snack.getdirc() != face.right)
         {
             input = face.left;
         }
     }
     else if (e.KeyChar == 'w')
     {
         if (Snack.getdirc() != face.up)
         {
             input = face.down;
         }
     }
 }
Beispiel #2
0
 public bool walk(face t)
 {
     if (t == face.down)
     {
         x -= 1;
     }
     if (t == face.up)
     {
         x += 1;
     }
     if (t == face.left)
     {
         y -= 1;
     }
     if (t == face.right)
     {
         y += 1;
     }
     if (x < GamePage.maxW && x > 0 && y < GamePage.maxH && y > 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
 public void Connect_to_Face(face f)
 {
     if (connected_faces.Count < 2)
     {
         connected_faces.Add(f);
         f.Connect_to_Edge(this);
     }
 }
 void Start()
 {
     time    = 0.5f;
     drawing = false;
     set     = new List <float>();
     curFace = face.top;
     pos     = new Vector3(0, 0, 0);
     indx    = 0;
 }
 public void clear()
 {
     foreach (Transform c in parent)
     {
         Destroy(c.gameObject);
     }
     pos     = Vector3.zero;
     curFace = face.top;
 }
Beispiel #6
0
            public Transform fold(face f1, edge e1, face f2)
            {
                Plane    p1, p2;
                Point3d  cen = this.From;
                Vector3d v   = this.To - this.From;

                p1 = new Plane(cen, v, f1.Normal);
                p2 = new Plane(cen, v, f2.Normal);
                return(Transform.PlaneToPlane(p1, p2));
            }
Beispiel #7
0
 public bool ContrastFace(face a, face b)
 {
     if ((a == face.up && b == face.down) || (a == face.down && b == face.up) ||
         (a == face.left && b == face.right) ||
         (a == face.right && b == face.left))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #8
0
 public void flip()
 {
     if (face == (face)1)
     {
         face        = (face) - 1;
         textureName = suitN + valueN;
     }
     else
     {
         face        = (face)1;
         textureName = backN;
     }
     texture = game.Content.Load <Texture2D>(textureName);
 }
Beispiel #9
0
        public static string Flood_Fill(Vector3 furthest_from_face, face current_face, Stack <edge> horizon_edge_list, Stack <face> visited_faces)
        {
            UnityEngine.Debug.Log("Flooding... " + current_face);
            string path = "";
            face   next_face;
            face   last_face;

            if (visited_faces.Count > 0)
            {
                last_face = visited_faces.Peek();
                // Testing if face is a conflict (not visible or already visited)
                // There is some conflict, either the current face has already been visited or it is not visible from the point
                if (visited_faces.Contains(current_face))
                {
                    return("C");
                }
                if (!current_face.Is_Visible_from_Point(furthest_from_face))
                {
                    // Adding the relevant edge to the edge list
                    horizon_edge_list.Push(current_face.edges.Find(element1 => element1.connected_faces.Exists(element2 => element2 == last_face)));
                    UnityEngine.Debug.Log("INTREST: " + horizon_edge_list.Peek().connected_faces.Exists(element2 => visited_faces.Contains(element2)));
                    return("H");
                }
            }
            else
            {
                if (!current_face.Is_Visible_from_Point(furthest_from_face))
                {
                    return("H");
                }
            }
            visited_faces.Push(current_face);
            path += 'V';
            foreach (edge e in current_face.edges)
            {
                next_face = e.connected_faces.Find(element => element != current_face);
                path     += '[';
                path     += Flood_Fill(furthest_from_face, next_face, horizon_edge_list, visited_faces);
                path     += ']';
            }
            return(path);
        }
Beispiel #10
0
 public void FaceLoop(face f)
 {
     if (f.ID != -1)
     {
         ///////////
         // Print("00000002");
         f.ID = -1; f.Fold();
         for (int i = 0; i < f.edges.Length; i++)
         {
             edge e = f.edges[i];
             if (e.ID != -1)
             {
                 e.ID = -1;
                 if (e.Faces.Length == 2)
                 {
                     face f2;
                     if (f.EqualTo(e.Faces[0]))
                     {
                         f2 = e.Faces[1];
                     }
                     else
                     {
                         f2 = e.Faces[0];
                     }
                     if (f2.ID != -1)
                     {
                         //Print(f2.ID.ToString());
                         f2.AddTransform(f.Xform);
                         f2.AddTransform(e.fold(f2, e, f));
                         FaceLoop(f2);
                     }
                 }
             }
         }
         //////
     }
 }
 void Update()
 {
     if (drawing && set.Count > 0)
     {
         if (deltaT >= time)
         {
             deltaT = 0f;
             updateVectors();
             for (int i = 0; i < set[indx]; i++)
             {
                 GameObject g = Instantiate(unit);
                 g.transform.SetParent(parent);
                 g.transform.position = pos;
                 pos += posOff;
                 g.transform.rotation = Quaternion.Euler(rot);
             }
             if (curFace == face.right)
             {
                 curFace = face.top;
             }
             else
             {
                 curFace += 1;
             }
             indx++;
             if (indx >= set.Count)
             {
                 indx = 0;
             }
         }
         else
         {
             deltaT += Time.deltaTime;
         }
     }
 }
Beispiel #12
0
        public static string Flood_Fill_and_Make(Vector3 furthest_from_face, face current_face, Stack <edge> horizon_edge_list, Stack <face> visited_faces, List <face> daughter_faces)
        {
            UnityEngine.Debug.Log("Flooding... " + current_face);
            if (visited_faces.Count > 0)
            {
                // Testing if face is a conflict (not visible or already visited)
                // There is some conflict, either the current face has already been visited or it is not visible from the point
                if (visited_faces.Contains(current_face))
                {
                    return("C");
                }
                if (!current_face.Is_Visible_from_Point(furthest_from_face))
                {
                    face last_face    = visited_faces.Peek();
                    edge horizon_edge = current_face.edges.Find(element1 => element1.connected_faces.Exists(element2 => element2 == last_face));
                    UnityEngine.Debug.Log("last face: " + last_face);
                    UnityEngine.Debug.Log("current face: " + current_face);

                    // Adding the relevant edge to the edge list
                    horizon_edge_list.Push(horizon_edge);
                    List <Vector3> new_face_corners = new List <Vector3>(horizon_edge.vertices);
                    new_face_corners.Add(furthest_from_face);
                    //new stuff - generate and filter

                    var possible_faces = from c1 in new_face_corners
                                         from c2 in new_face_corners
                                         from c3 in new_face_corners
                                         where c1 != c2 && c1 != c3 && c2 != c3
                                         select new face(c1, c2, c3);

                    var front_facing_faces = from t in possible_faces
                                             where Distance_from_Plane(t.corners[0], t.corners[1] - t.corners[0], t.corners[2] - t.corners[0], Array.Find(last_face.corners, corner => !Array.Exists(t.corners, c => c == corner)), false) < 0
                                             select t;

                    var new_face = front_facing_faces.First();



                    // Modify horizon edges so they point to new face
                    horizon_edge.connected_faces.Remove(last_face);
                    horizon_edge.Connect_to_Face(new_face);
                    daughter_faces.Add(new_face);
                    UnityEngine.Debug.Log("ITEM: ");

                    return("H");
                }
            }
            else
            {
                if (!current_face.Is_Visible_from_Point(furthest_from_face))
                {
                    return("H");
                }
            }
            string path = "";

            UnityEngine.Debug.Log("Visit: ");
            path += 'V';
            foreach (edge e in current_face.edges)
            {
                visited_faces.Push(current_face);
                //testing
                if (e.connected_faces.Count < 2 || !e.connected_faces.Contains(current_face))
                {
                    UnityEngine.Debug.Log("WARNING, MAKING ONE WAY TRIP: " + !e.connected_faces.Contains(current_face));
                }
                UnityEngine.Debug.Log("Flag: " + !e.connected_faces.Contains(current_face));
                UnityEngine.Debug.Log("current face: " + current_face);
                UnityEngine.Debug.Log("top of stack: " + visited_faces.Peek());
                UnityEngine.Debug.Log("traversing edge: " + e);
                //testing
                face next_face = e.connected_faces.Find(element => element != current_face);
                UnityEngine.Debug.Log("next face: " + next_face);
                path += '[';
                path += Flood_Fill_and_Make(furthest_from_face, next_face, horizon_edge_list, visited_faces, daughter_faces);
                path += ']';
            }
            return(path);
        }
Beispiel #13
0
        public void CreateModelObject(int index)
        {
            int numFaces  = map.modelsLump[index].numfaces;
            int firstFace = map.modelsLump[index].firstface;


            //Debug.Log ("Model "+index+" Lightmaps count "+tempLightmaps.Length);

            GameObject model = new GameObject("*" + index);

            model.transform.parent = modelsObject.transform;
            Models.Add(model);
            model.isStatic = true;
            if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
            {
                model.layer = 8;
            }

            Vector3 origin = map.modelsLump[index].origin;

            if (origin != Vector3.zero)
            {
                Debug.Log("Model " + index + " on origin: " + origin.ToString());
            }

            //List<Vector3> verts=new List<Vector3>();
            //List<Vector2> UVs=new List<Vector2>();
            //List<Vector2> UV2s=new List<Vector2>();
            //List<int> tris = new List<int>();

            bspface    face;
            bsptexdata texdata;

            if (uSrcSettings.Inst.textures)
            {
                //Debug.Log ("Start calc tex faces");
                for (int i = firstFace; i < firstFace + numFaces; i++)
                {
                    face    = map.facesLump[i];
                    texdata = map.texdataLump[map.texinfosLump[face.texinfo].texdata];
                    if (texdata.faces == null)
                    {
                        //Debug.Log ("Texdata faces is null. Init");
                        if ((map.texinfosLump[face.texinfo].flags & 4) == 0)
                        {
                            texdata.faces = new List <int>();
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (face.dispinfo == -1)
                    {
                        texdata.faces.Add(i);
                        texdata.numvertices += face.numedges;
                    }
                }
            }
            //int numlightfaces = numFaces;
            if (!uSrcSettings.Inst.textures)
            {
                Texture2D modelLightmap = null;
                //Texture2D[] tempLightmaps = null;
                List <Texture2D> tempLightmaps = null;
                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                {
                    tempLightmaps = new List <Texture2D>();
                    //tempLightmaps = new Texture2D[numFaces > maxLMs ? maxLMs : numFaces];
                    modelLightmap = new Texture2D(64, 64, TextureFormat.RGB24, true, true);
                }

                List <Vector3> verts = new List <Vector3>();
                List <Vector2> UVs   = new List <Vector2>();
                List <Vector2> UV2s  = new List <Vector2>();
                List <int>     tris  = new List <int>();

                for (int i = firstFace; i < firstFace + numFaces; i++)
                {
                    face f = BuildFace(i);

                    if ((f.flags & 4) != 0)
                    {
                        continue;
                    }
                    //if ((f.flags & 1024) != 0)
                    //	numlightfaces--;

                    int pointOffs = verts.Count;
                    for (int j = 0; j < f.triangles.Length; j++)
                    {
                        tris.Add(f.triangles [j] + pointOffs);
                    }

                    verts.AddRange(f.points);
                    UVs.AddRange(f.uv);
                    UV2s.AddRange(f.uv2);

                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps /*&&(f.flags & 1024) != 0*/)
                    {
                        if (i < firstFace + maxLMs)
                        {
                            tempLightmaps.Add(CreateLightmapTex(f));
                        }
                    }
                }

                if (numFaces > 0)
                {
                    //GameObject faceObject = new GameObject ("Face: "+index);
                    //faceObject.transform.parent = Models[model].transform;
                    Rect[] offsets = null;
                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                    {
                        offsets = modelLightmap.PackTextures(tempLightmaps.ToArray(), 1);

                        for (int i = 0; i < tempLightmaps.Count; i++)
                        {
                            Destroy(tempLightmaps[i]);
                        }
                        tempLightmaps.Clear();
                    }
                    tempLightmaps = null;

                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                    {
                        int curVert = 0;
                        int curRect = 0;

                        //Debug.Log ("Offsets count "+offsets.Length);

                        for (int i = 0; i < numFaces; i++)
                        {
                            int flags = map.texinfosLump [map.facesLump [i + firstFace].texinfo].flags;
                            if ((flags & 4) != 0)
                            {
                                continue;
                            }

                            int  numVerts = map.facesLump[firstFace + i].numedges;
                            Rect offs     = offsets[curRect];

                            for (int v = curVert; v < curVert + numVerts; v++)
                            {
                                if (i < maxLMs)
                                {
                                    Vector2 tempUV = UV2s[v];
                                    UV2s[v] = new Vector2((tempUV.x * offs.width) + offs.x, (tempUV.y * offs.height) + offs.y);
                                }
                                else
                                {
                                    UV2s[v] = new Vector2(0.9f, 0.9f);
                                }
                            }
                            curVert += numVerts;
                            curRect++;
                        }

                        lightmapsData.Add(new LightmapData()
                        {
                            lightmapFar = modelLightmap
                        });
                    }
                    //Material mat = new Material(Shader.Find ("Mobile/Diffuse"));


                    MeshRenderer mr = model.AddComponent <MeshRenderer>();
                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                    {
                        mr.lightmapIndex = curLightmap;
                        curLightmap++;
                        //mr.lightmapIndex=lightmapsData.Count-1;[
                    }
                    mr.material = Test.Inst.testMaterial;

                    MeshFilter mf = model.AddComponent <MeshFilter>();

                    mf.mesh           = new Mesh();
                    mf.mesh.name      = "BSPModel_" + index;
                    mf.mesh.vertices  = verts.ToArray();
                    mf.mesh.triangles = tris.ToArray();
                    mf.mesh.uv        = UVs.ToArray();
                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                    {
                        mf.mesh.uv2 = UV2s.ToArray();
                    }

                    mf.mesh.RecalculateNormals();

                    if (uSrcSettings.Inst.genColliders)
                    {
                        model.AddComponent <MeshCollider>();
                    }
                }
            }
            else
            {
                List <Texture2D> tempLightmaps = null;
                Texture2D        modelLightmap = null;

                List <Mesh> texMeshes = new List <Mesh>();
                //Mesh testMesh=null;

                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                {
                    tempLightmaps = new List <Texture2D>();
                    modelLightmap = new Texture2D(64, 64, TextureFormat.RGB24, true, true);
                }

                for (int i = 0; i < map.texdataLump.Length; i++)
                {
                    texdata = map.texdataLump[i];

                    if (texdata.faces == null)
                    {
                        //Debug.Log("TexData "+i+" has no faces");
                        continue;
                    }

                    List <Vector3> verts = new List <Vector3>();
                    List <Vector2> UVs   = new List <Vector2>();
                    List <Vector2> UV2s  = new List <Vector2>();
                    List <int>     tris  = new List <int>();

                    for (int j = 0; j < texdata.faces.Count; j++)
                    {
                        face = map.facesLump[texdata.faces[j]];

                        face f = BuildFace(texdata.faces[j]);

                        //if ((f.flags & 1024) != 0)
                        //numlightfaces--;

                        int pointOffs = verts.Count;
                        for (int t = 0; t < f.triangles.Length; t++)
                        {
                            tris.Add(f.triangles [t] + pointOffs);
                        }

                        verts.AddRange(f.points);
                        UVs.AddRange(f.uv);
                        if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                        {
                            UV2s.AddRange(f.uv2);
                        }

                        //	if (i < firstFace + maxLMs)
                        //		tempLightmaps [i - firstFace] = CreateLightmapTex (f);

                        if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                        {
                            if (j < maxLMs)
                            {
                                tempLightmaps.Add(CreateLightmapTex(f));
                            }
                        }
                    }

                    string materialName = "";
                    if (map.texdataStringDataLump.Length > map.texdataStringTableLump [texdata.nameStringTableID] + 92)
                    {
                        materialName = new string (map.texdataStringDataLump, map.texdataStringTableLump [texdata.nameStringTableID], 92);
                    }
                    else
                    {
                        materialName = new string (map.texdataStringDataLump, map.texdataStringTableLump [texdata.nameStringTableID], map.texdataStringDataLump.Length - map.texdataStringTableLump [texdata.nameStringTableID]);
                    }

                    materialName = materialName.ToLower();

                    if (materialName.Contains("\0"))
                    {
                        materialName = materialName.Remove(materialName.IndexOf('\0'));
                    }

                    GameObject texObj;
                    if (texdata.faces == null)
                    {
                        texObj = model;
                    }
                    else
                    {
                        texObj = new GameObject(materialName);
                        texObj.transform.SetParent(model.transform);
                    }
                    texObj.isStatic = true;
                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                    {
                        texObj.layer = 8;
                    }

                    MeshRenderer mr   = texObj.AddComponent <MeshRenderer>();
                    MeshFilter   mf   = texObj.AddComponent <MeshFilter>();
                    Mesh         mesh = new Mesh();


                    mesh.name     = materialName;
                    mesh.vertices = verts.ToArray();
                    mesh.uv       = UVs.ToArray();

                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                    {
                        mesh.uv2 = UV2s.ToArray();
                    }

                    mesh.triangles = tris.ToArray();
                    mesh.RecalculateNormals();
                    //mf.sharedMesh = mesh;
                    mf.mesh = mesh;

                    texMeshes.Add(mf.sharedMesh);

                    Material tempmat = ResourceManager.Inst.GetMaterial(materialName);
                    mr.material = tempmat;

                    if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                    {
                        mr.lightmapIndex = curLightmap;
                    }
                    if ((materialName.Contains("trigger") || materialName.Contains("fogvolume")) && !uSrcSettings.Inst.showTriggers)
                    {
                        texObj.SetActive(false);
                    }

                    if (uSrcSettings.Inst.genColliders)
                    {
                        texObj.AddComponent <MeshCollider>();
                    }
                }

                //if(texMeshes.Count>0)
                //	Debug.Log ("First Mesh is "+texMeshes[0].name);

                Rect[] offsets = null;
                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)
                {
                    offsets = modelLightmap.PackTextures(tempLightmaps.ToArray(), 1);
                    //Debug.Log ("tempLightmaps count "+tempLightmaps.Count);

                    for (int l = 0; l < tempLightmaps.Count; l++)
                    {
                        Destroy(tempLightmaps[l]);
                    }
                    tempLightmaps.Clear();

                    int curMesh  = 0;
                    int curVert  = 0;
                    int numVerts = 0;
                    int curRect  = 0;

                    for (int t = 0; t < map.texdataLump.Length; t++)
                    {
                        texdata = map.texdataLump[t];

                        if (texdata.faces == null)
                        {
                            continue;
                        }

                        Mesh mesh = texMeshes[curMesh];
                        curMesh++;
                        Vector2[] uv2 = mesh.uv2;

                        //int flags=map.texinfosLump [face.texinfo].flags;

                        for (int f = 0; f < texdata.faces.Count; f++)
                        {
                            if (curRect > offsets.Length)
                            {
                                Debug.Log("curent offset(" + curRect + ") > offsets count");
                                break;
                            }

                            if (curVert > uv2.Length)
                            {
                                Debug.Log("vert index > uv2 count");
                                break;
                            }

                            face     = map.facesLump[texdata.faces[f]];
                            numVerts = face.numedges;
                            Rect offs = offsets[curRect];
                            curRect++;
                            for (int v = curVert; v < curVert + numVerts; v++)
                            {
                                Vector2 tempUV = uv2[v];
                                uv2[v] = new Vector2((tempUV.x * offs.width) + offs.x, (tempUV.y * offs.height) + offs.y);
                            }
                            curVert += numVerts;
                        }
                        curVert  = 0;
                        mesh.uv2 = uv2;


                        texdata.faces.Clear();
                        texdata.faces = null;
                    }

                    lightmapsData.Add(new LightmapData()
                    {
                        lightmapFar = modelLightmap
                    });
                    curLightmap++;
                }
                else
                {
                    for (int t = 0; t < map.texdataLump.Length; t++)
                    {
                        texdata = map.texdataLump[t];

                        if (texdata.faces == null)
                        {
                            continue;
                        }

                        texdata.faces.Clear();
                        texdata.faces = null;
                    }
                }

                texMeshes.Clear();
                texMeshes = null;
            }
        }
Beispiel #14
0
        Texture2D CreateLightmapTex(face f)
        {
            int       rowColors = f.lightMapW;
            Texture2D tex       = new Texture2D(f.lightMapW, f.lightMapH, TextureFormat.RGB24, false, true);

            //tex.filterMode = FilterMode.Point;
            //Color32[] colors32 = new Color32[(f.lightMapW) * (f.lightMapH)];
            Color[] colors = new Color[(f.lightMapW) * (f.lightMapH)];

            int Offset = map.facesLump [f.index].lightofs / 4;

            if (map.facesLump [f.index].lightofs < 0 | map.lightingLump.Length == 0)
            {
                return(null);
            }

            int o = 0;
            int j = 0;

            for (int y = 0; y < f.lightMapH; y++)
            {
                o = (rowColors * (y));
                for (int x = 0; x < f.lightMapW; x++)
                {
                    RGBExp32 col = map.lightingLump[Offset + j++];

                    /*colors32[o] = new Color32(TexLightToLinearB(col.r, col.exp),
                     *                                              TexLightToLinearB(col.g, col.exp),
                     *                                              TexLightToLinearB(col.b, col.exp),
                     *                                                         255);*/
                    float exp = (float)Mathf.Pow(2, col.exp);
                    colors[o] = new Color(TexLightToLinearF(col.r, exp),
                                          TexLightToLinearF(col.g, exp),
                                          TexLightToLinearF(col.b, exp),
                                          1f);

                    o++;
                }
            }
            //=======fill borders================

            /*
             * for(int y=0; y<f.lightMapH+1;y++)
             * {
             *      o=rowColors * y;
             *      colors[o] = colors[o+1];
             *
             *      o=(rowColors * (y+1))-1;
             *      colors[o] = colors[o-1];
             * }
             *
             * int end=(f.lightMapW+2)*(f.lightMapH+2);
             * for(int x=0; x<f.lightMapW+2;x++)
             * {
             *      colors[x] = colors[x+rowColors];
             *      colors[(end-rowColors)+x] = colors[(end-(rowColors*2)+x)];
             * }
             */
            //=====================================

            //tex.SetPixels32 (colors32);
            tex.SetPixels(colors);
            tex.Apply();
            return(tex);
        }
Beispiel #15
0
 public bool EqualTo(face f1)
 {
     return(this.ID == f1.ID);
 }
Beispiel #16
0
        void GenerateFaceObject(int index, int model)
        {
            //List<Vector3> verts=new List<Vector3>();
            //List<Vector2> UVs=new List<Vector2>();
            //List<Vector2> lightmapUV=new List<Vector2>();
            //List<int> tris = new List<int>();

            face f = BuildFace(index);
            //f.index = index;

            //if((f.flags & 4) == 4)
            //	return;



            //tris.AddRange (f.triangles);
            //verts.AddRange (f.points);
            //UVs.AddRange (f.uv);
            //lightmapUV.AddRange(f.uv2);

            GameObject faceObject = new GameObject("Face: " + index);

            MeshRenderer mr = faceObject.AddComponent <MeshRenderer>();

            //Material mat;
            MeshFilter mf = faceObject.AddComponent <MeshFilter>();

            mf.mesh           = new Mesh();
            mf.mesh.name      = "BSPFace " + index;
            mf.mesh.vertices  = f.points;
            mf.mesh.triangles = f.triangles;
            mf.mesh.uv        = f.uv;



            //=======================//?????????

            /*
             * Vector4[] tang = new Vector4[verts.Count];
             * for (int i=0; i<verts.Count; i++)
             *      tang [i] = new Vector4 (0, 0, 1);
             *
             * mf.mesh.tangents = tang;
             */
            //========================

            if (uSrcSettings.Inst.textures)
            {
                bsptexdata curTexData = map.texdataLump[map.texinfosLump[map.facesLump[index].texinfo].texdata];

                //===========================Material=============================
                string materialName = "";
                //VMTLoader.VMTFile vmtFile=null;
                //Material tempmat=null;

                //string
                if (map.texdataStringDataLump.Length > map.texdataStringTableLump [curTexData.nameStringTableID] + 92)
                {
                    materialName = new string (map.texdataStringDataLump, map.texdataStringTableLump [curTexData.nameStringTableID], 92);
                }
                else
                {
                    materialName = new string (map.texdataStringDataLump, map.texdataStringTableLump [curTexData.nameStringTableID], map.texdataStringDataLump.Length - map.texdataStringTableLump [curTexData.nameStringTableID]);
                }

                materialName = materialName.ToLower();

                if (materialName.Contains("\0"))
                {
                    materialName = materialName.Remove(materialName.IndexOf('\0'));
                }

                //return VMTLoader.GetMaterial (materialName);

                Material tempmat = ResourceManager.Inst.GetMaterial(materialName);
                //=================Material End========================


                //if (tempmat.name.Contains ("trigger")||tempmat.name.Contains ("fogvolume")||tempmat.name.Contains ("tools/toolsskybox"))
                //	mr.enabled = false;

                mr.material = tempmat;

                if (uSrcSettings.Inst.lightmaps && map.hasLightmaps)                // & !vmtFile.translucent)
                {
                    //Texture2D lightMap = CreateLightmapTex (f);

                    mf.mesh.uv2      = f.uv2;
                    mr.lightmapIndex = 0;
                }
            }
            else
            {
                mr.material = Test.Inst.testMaterial;
            }

            mf.mesh.RecalculateNormals();
            //mf.mesh.RecalculateBounds ();

            //faceObject.transform.parent = Models[model].transform;
            faceObject.transform.SetParent(modelsObject.transform);
            mf.mesh.Optimize();
            faceObject.isStatic = true;
        }
Beispiel #17
0
        face BuildDispFace(int faceIndex, int model, short dispinfoId)
        {
            Vector3[]      vertices   = new Vector3[4];
            List <Vector3> disp_verts = new List <Vector3>();
            List <Vector2> UVs        = new List <Vector2>();
            List <int>     indices    = new List <int>();

            bspface curFace = map.facesLump[faceIndex];

            bsptexinfo curTexInfo = map.texinfosLump[curFace.texinfo];
            bsptexdata curTexData = map.texdataLump[curTexInfo.texdata];


            int fEdge = curFace.firstedge;

            for (int i = 0; i < curFace.numedges; i++)
            {
                vertices[i] = (map.surfedgesLump[fEdge + i] > 0 ?
                               map.vertexesLump[map.edgesLump[Mathf.Abs(map.surfedgesLump[fEdge + i])][0]] :
                               map.vertexesLump[map.edgesLump[Mathf.Abs(map.surfedgesLump[fEdge + i])][1]]);
            }

            bspdispinfo curDisp  = map.dispinfoLump [dispinfoId];
            Vector3     startPos = curDisp.startPosition;

            float dist;
            float minDist  = 0.1f;
            int   minIndex = 0;

            for (int i = 0; i < 4; i++)
            {
                dist = Vector3.Distance(startPos, vertices[i]);

                if (dist < minDist)
                {
                    minDist  = dist;
                    minIndex = i;
                }
            }

            Vector3 temp;

            for (int i = 0; i < minIndex; i++)
            {
                temp        = vertices[0];
                vertices[0] = vertices[1];
                vertices[1] = vertices[2];
                vertices[2] = vertices[3];
                vertices[3] = temp;
            }

            Vector3 leftEdge  = vertices[1] - vertices[0];
            Vector3 rightEdge = vertices[2] - vertices[3];


            int numEdgeVertices = (1 << curDisp.power) + 1;

            float subdivideScale = 1.0f / (float)(numEdgeVertices - 1);

            Vector3 leftEdgeStep  = leftEdge * subdivideScale;
            Vector3 rightEdgeStep = rightEdge * subdivideScale;

            int firstVertex = 0;

            Vector3 leftEnd;
            Vector3 rightEnd;
            Vector3 leftRightSeg;
            Vector3 leftRightStep;

            int         dispVertIndex;
            bspDispVert dispVert;

            Vector3 flatVertex;
            Vector3 dispVertex;

            float scaleU = (float)1f / curTexData.width;
            float scaleV = (float)1f / curTexData.height;

            for (int i = 0; i < numEdgeVertices; i++)
            {
                leftEnd   = leftEdgeStep * (float)i;
                leftEnd  += vertices[0];
                rightEnd  = rightEdgeStep * (float)i;
                rightEnd += vertices[3];

                leftRightSeg  = rightEnd - leftEnd;
                leftRightStep = leftRightSeg * subdivideScale;

                for (int j = 0; j < numEdgeVertices; j++)
                {
                    dispVertIndex  = curDisp.DispVertStart;
                    dispVertIndex += i * numEdgeVertices + j;
                    dispVert       = map.dispVertsLump[dispVertIndex];

                    flatVertex = leftEnd + (leftRightStep * (float)j);

                    dispVertex  = dispVert.vec * (dispVert.dist /* *scale*/);
                    dispVertex += flatVertex;

                    disp_verts.Add(dispVertex);


                    float tU = Vector3.Dot(flatVertex, curTexInfo.texvecs) + (curTexInfo.texoffs);
                    float tV = Vector3.Dot(flatVertex, curTexInfo.texvect) + (curTexInfo.texofft);
                    UVs.Add(new Vector2(tU * scaleU, tV * scaleV));
                }
            }

            int curIndex;

            for (int i = 0; i < numEdgeVertices - 1; i++)
            {
                for (int j = 0; j < numEdgeVertices - 1; j++)
                {
                    curIndex = i * numEdgeVertices + j;

                    if ((curIndex % 2) == 1)
                    {
                        curIndex += firstVertex;

                        indices.Add(curIndex + 1);
                        indices.Add(curIndex);
                        indices.Add(curIndex + numEdgeVertices);
                        indices.Add(curIndex + numEdgeVertices + 1);
                        indices.Add(curIndex + 1);
                        indices.Add(curIndex + numEdgeVertices);
                    }
                    else
                    {
                        curIndex += firstVertex;

                        indices.Add(curIndex);
                        indices.Add(curIndex + numEdgeVertices);
                        indices.Add(curIndex + numEdgeVertices + 1);
                        indices.Add(curIndex + 1);
                        indices.Add(curIndex);
                        indices.Add(curIndex + numEdgeVertices + 1);
                    }
                }
            }


            for (int i = 0; i < disp_verts.Count; i++)
            {
                disp_verts[i] *= uSrcSettings.Inst.worldScale;
            }


            face f = new face();

            //f.lightMapW = lightmapW;
            //f.lightMapH = lightmapH;
            f.points    = disp_verts.ToArray();
            f.triangles = indices.ToArray();;
            f.uv        = UVs.ToArray();
            //f.uv2 = UV2s;
            //f.flags = flags;
            f.index    = faceIndex;
            f.dispinfo = dispinfoId;

            return(f);
        }
        public MainWindow()
        {
            InitializeComponent();

            //temp = sr.ToString();
            //temp1 = temp.Split(' ').ToString();
            //MessageBox.Show(temp1);
            //for(int i= 1; i<1001; i++)
            while (!srt.EndOfStream)
            {
                line  = srt.ReadLine().ToString();
                hand1 = line.Substring(0, 14);
                hand2 = line.Substring(15, 14);



                string[] Hand1Cards  = new string[5];
                suits[]  Hand1Suites = new suits[5];
                face[]   Hand1Face   = new face[5];
                string[] Hand2Cards  = new string[5];
                suits[]  Hand2Suites = new suits[5];
                face[]   Hand2Face   = new face[5];
                for (int j = 0; j < Hand1Cards.Length; j++)
                {
                    Hand1Cards[j] = hand1.Substring(j * 3, 2);
                    switch (Hand1Cards[j][0])
                    {
                    case 'A': Hand1Face[j] = face.Ace; break;

                    case '2': Hand1Face[j] = face.Two; break;

                    case '3': Hand1Face[j] = face.Three; break;

                    case '4': Hand1Face[j] = face.Four; break;

                    case '5': Hand1Face[j] = face.Five; break;

                    case '6': Hand1Face[j] = face.Six; break;

                    case '7': Hand1Face[j] = face.Seven; break;

                    case '8': Hand1Face[j] = face.Eight; break;

                    case '9': Hand1Face[j] = face.Nine; break;

                    case 'T': Hand1Face[j] = face.Ten; break;

                    case 'J': Hand1Face[j] = face.Jack; break;

                    case 'Q': Hand1Face[j] = face.Queen; break;

                    case 'K': Hand1Face[j] = face.King; break;
                    }
                    switch (Hand1Cards[j][1])
                    {
                    case 'D': Hand1Suites[j] = suits.Diamonds; break;

                    case 'H': Hand1Suites[j] = suits.Heart; break;

                    case 'C': Hand1Suites[j] = suits.Clubs; break;

                    case 'S': Hand1Suites[j] = suits.Spades; break;
                    }


                    //     MessageBox.Show(Hand1Face[j].ToString() + Hand1Suites[j].ToString());
                }
                for (int j = 0; j < Hand2Cards.Length; j++)
                {
                    Hand2Cards[j] = hand2.Substring(j * 3, 2);
                    switch (Hand2Cards[j][0])
                    {
                    case 'A': Hand2Face[j] = face.Ace; break;

                    case '2': Hand2Face[j] = face.Two; break;

                    case '3': Hand2Face[j] = face.Three; break;

                    case '4': Hand2Face[j] = face.Four; break;

                    case '5': Hand2Face[j] = face.Five; break;

                    case '6': Hand2Face[j] = face.Six; break;

                    case '7': Hand2Face[j] = face.Seven; break;

                    case '8': Hand2Face[j] = face.Eight; break;

                    case '9': Hand2Face[j] = face.Nine; break;

                    case 'T': Hand2Face[j] = face.Ten; break;

                    case 'J': Hand2Face[j] = face.Jack; break;

                    case 'Q': Hand2Face[j] = face.Queen; break;

                    case 'K': Hand2Face[j] = face.King; break;
                    }
                    switch (Hand2Cards[j][1])
                    {
                    case 'D': Hand2Suites[j] = suits.Diamonds; break;

                    case 'H': Hand2Suites[j] = suits.Heart; break;

                    case 'C': Hand2Suites[j] = suits.Clubs; break;

                    case 'S': Hand2Suites[j] = suits.Spades; break;
                    }


                    //     MessageBox.Show(Hand2Face[j].ToString() + Hand1Suites[j].ToString());
                }

                Array.Sort(Hand1Face);
                string output = "";
                for (int i = 0; i < Hand1Face.Length; i++)
                {
                    output += Hand1Face[i];
                }
                MessageBox.Show(output);
                //MessageBox.Show((face.Ace - face.King).ToString());
                ScoreP1 = 0;
                ScoreP2 = 0;
                if (Hand1Suites[0] == Hand1Suites[1] && Hand1Suites[0] == Hand1Suites[2] && Hand1Suites[0] == Hand1Suites[3] && Hand1Suites[0] == Hand1Suites[4])
                {
                    if (Hand1Face[0] == face.Ace)
                    {
                        CheckForFlushes(Hand1Face);
                    }
                    if (Hand1Face[0] != face.Ace)
                    {
                        CheckForStraightFlush(Hand1Face);
                    }
                    if (ScoreP1 == 0)
                    {
                        ScoreP1 = 6;
                    }
                }
                if (Hand1Face[0] == Hand1Face[1])
                {
                    if (Hand1Face[0] == Hand1Face[2])
                    {
                        if (Hand1Face[3] == Hand1Face[4])
                        {
                            ScoreP1 = 7;
                        }
                    }
                }
                if (Hand1Face[2] == Hand1Face[3])
                {
                    if (Hand1Face[2] == Hand1Face[4])
                    {
                        if (Hand1Face[0] == Hand1Face[1])
                        {
                            ScoreP1 = 7;
                        }
                    }
                }

                if (Hand1Face[0] == Hand1Face[1])
                {
                    if (Hand1Face[0] == Hand1Face[2])
                    {
                        if (Hand1Face[0] == Hand1Face[3])
                        {
                            ScoreP1 = 8;
                        }
                        else
                        {
                            ScoreP1 = 4;
                        }
                    }
                    else
                    {
                        if (ScoreP1 == 3)
                        {
                            break;
                        }
                        else
                        {
                            ScoreP1 = 2;
                        }
                    }
                }
                if (Hand1Face[1] == Hand1Face[2])
                {
                    if (Hand1Face[1] == Hand1Face[3])
                    {
                        if (Hand1Face[1] == Hand1Face[4])
                        {
                            ScoreP1 = 8;
                        }
                        else
                        {
                            ScoreP1 = 4;
                        }
                    }
                    else
                    {
                        if (ScoreP1 == 3)
                        {
                            break;
                        }
                        else
                        {
                            ScoreP1 = 2;
                        }
                    }
                }
                if (Hand1Face[0] == Hand1Face[1] && Hand1Face[2] == Hand1Face[3])
                {
                    ScoreP1 = 3;
                }
                if (Hand1Face[1] == Hand1Face[2] && Hand1Face[3] == Hand1Face[4])
                {
                    ScoreP1 = 3;
                }
                if (Hand1Face[0] == Hand1Face[1] && Hand1Face[3] == Hand1Face[4])
                {
                    ScoreP1 = 3;
                }
                if (Hand1Face[2] == Hand1Face[3])
                {
                    if (Hand1Face[2] == Hand1Face[4])
                    {
                        ScoreP1 = 4;
                    }
                }
                else
                {
                    if (ScoreP1 == 3)
                    {
                        break;
                    }
                    else
                    {
                        ScoreP1 = 2;
                    }
                }
                if (Hand1Face[3] == Hand1Face[4])
                {
                    if (ScoreP1 == 3)
                    {
                        break;
                    }
                    else
                    {
                        ScoreP1 = 2;
                    }
                }
                if (Hand1Face[0] - Hand1Face[1] == -1 && Hand1Face[1] - Hand1Face[2] == -1 && Hand1Face[2] - Hand1Face[3] == -1 && Hand1Face[3] - Hand1Face[4] == -1)
                {
                    ScoreP1 = 5;
                }
                else
                {
                    ScoreP1 = 1;
                }



                Array.Sort(Hand2Face);
                string output2 = "";
                for (int i = 0; i < Hand2Face.Length; i++)
                {
                    output2 += Hand2Face[i];
                }
                MessageBox.Show(output2 + "P2");
                //MessageBox.Show((face.Ace - face.King).ToString());
                ScoreP1 = 0;
                if (Hand1Suites[0] == Hand1Suites[1] && Hand1Suites[0] == Hand1Suites[2] && Hand1Suites[0] == Hand1Suites[3] && Hand1Suites[0] == Hand1Suites[4])
                {
                    if (Hand2Face[0] == face.Ace)
                    {
                        //check if Ace, two,...five
                        if (Hand2Face[0] - Hand2Face[1] == -1 && Hand2Face[1] - Hand2Face[2] == -1 && Hand2Face[2] - Hand2Face[3] == -1 && Hand2Face[3] - Hand2Face[4] == -1)
                        {
                            ScoreP1 = 9;
                        }
                        else if (Hand2Face[0] - Hand2Face[4] == -12 && Hand2Face[1] - Hand2Face[2] == -1 && Hand2Face[2] - Hand2Face[3] == -1 && Hand2Face[3] - Hand2Face[4] == -1)
                        {
                            ScoreP1 = 10;
                        }
                    }
                    if (Hand2Face[0] != face.Ace)
                    {
                        if (Hand2Face[0] - Hand2Face[1] == -1 && Hand2Face[1] - Hand2Face[2] == -1 && Hand2Face[2] - Hand2Face[3] == -1 && Hand2Face[3] - Hand2Face[4] == -1)
                        {
                            ScoreP1 = 9;
                        }
                    }
                    if (ScoreP1 == 0)
                    {
                        ScoreP1 = 6;
                    }
                }
                if (Hand2Face[0] == Hand2Face[1])
                {
                    if (Hand2Face[0] == Hand2Face[2])
                    {
                        if (Hand2Face[3] == Hand2Face[4])
                        {
                            ScoreP1 = 7;
                        }
                    }
                }
                if (Hand2Face[2] == Hand2Face[3])
                {
                    if (Hand2Face[2] == Hand2Face[4])
                    {
                        if (Hand2Face[0] == Hand2Face[1])
                        {
                            ScoreP1 = 7;
                        }
                    }
                }

                if (Hand2Face[0] == Hand2Face[1])
                {
                    if (Hand2Face[0] == Hand2Face[2])
                    {
                        if (Hand2Face[0] == Hand2Face[3])
                        {
                            ScoreP1 = 8;
                        }
                        else
                        {
                            ScoreP1 = 4;
                        }
                    }
                    else
                    {
                        if (ScoreP1 == 3)
                        {
                            break;
                        }
                        else
                        {
                            ScoreP1 = 2;
                        }
                    }
                }
                if (Hand2Face[1] == Hand2Face[2])
                {
                    if (Hand2Face[1] == Hand2Face[3])
                    {
                        if (Hand2Face[1] == Hand2Face[4])
                        {
                            ScoreP1 = 8;
                        }
                        else
                        {
                            ScoreP1 = 4;
                        }
                    }
                    else
                    {
                        if (ScoreP1 == 3)
                        {
                            break;
                        }
                        else
                        {
                            ScoreP1 = 2;
                        }
                    }
                }
                if (Hand2Face[0] == Hand2Face[1] && Hand2Face[2] == Hand2Face[3])
                {
                    ScoreP1 = 3;
                }
                if (Hand2Face[1] == Hand2Face[2] && Hand2Face[3] == Hand2Face[4])
                {
                    ScoreP1 = 3;
                }
                if (Hand2Face[0] == Hand2Face[1] && Hand2Face[3] == Hand2Face[4])
                {
                    ScoreP1 = 3;
                }
                if (Hand2Face[2] == Hand2Face[3])
                {
                    if (Hand2Face[2] == Hand2Face[4])
                    {
                        ScoreP1 = 4;
                    }
                }
                else
                {
                    if (ScoreP1 == 3)
                    {
                        break;
                    }
                    else
                    {
                        ScoreP1 = 2;
                    }
                }
                if (Hand2Face[3] == Hand2Face[4])
                {
                    if (ScoreP1 == 3)
                    {
                        break;
                    }
                    else
                    {
                        ScoreP1 = 2;
                    }
                }
                if (Hand2Face[0] - Hand2Face[1] == -1 && Hand2Face[1] - Hand2Face[2] == -1 && Hand2Face[2] - Hand2Face[3] == -1 && Hand2Face[3] - Hand2Face[4] == -1)
                {
                    ScoreP1 = 5;
                }
                else
                {
                    ScoreP1 = 1;
                }

                /*MessageBox.Show("works");
                 * for (int didntusethisi = 0; didntusethisi < Hand1Suites.Length; didntusethisi++)
                 * {
                 *  newOutput += ((face)Hand1Face[didntusethisi]).ToString() + "\n";
                 * }
                 * MessageBox.Show(newOutput);
                 *
                 * Array.Sort(Hand1Face);
                 * newOutput = "";
                 * for (int didntusethisi = 0; didntusethisi < Hand1Suites.Length; didntusethisi++)
                 * {
                 *  newOutput += ((face)Hand1Face[didntusethisi]).ToString() + "\n";
                 * }
                 * MessageBox.Show(newOutput);
                 *
                 * MessageBox.Show(((int)(Hand1Face[0] - Hand1Face[1])).ToString());*/
                MessageBox.Show(ScoreP1.ToString() + " " + ScoreP2.ToString());
            }
            WinnerLabel.Content = "Player 1 wins This many times: " + Player1Count;
        }
 public Transform fold(face f1, edge e1, face f2)
 {
     Plane p1, p2;
     Point3d cen = this.From;
     Vector3d v = this.To - this.From;
     p1 = new Plane(cen, v, f1.Normal);
     p2 = new Plane(cen, v, f2.Normal);
     return Transform.PlaneToPlane(p1, p2);
 }
 public bool EqualTo(face f1)
 {
     return this.ID == f1.ID;
 }
Beispiel #21
0
        face BuildFace(int index)
        {
            List <Vector3> verts = new List <Vector3>();
            List <Vector2> UVs   = new List <Vector2>();
            List <Vector2> UV2s  = new List <Vector2>();
            List <int>     tris  = new List <int>();

            bspface curface   = map.facesLump[index];
            int     startEdge = curface.firstedge;
            int     nEdges    = curface.numedges;
            //Debug.Log("texinfo "+curface.texinfo+"/"+map.texinfosLump.Length);
            int flags = map.texinfosLump [curface.texinfo].flags;

            for (int i = startEdge; i < startEdge + nEdges; i++)
            {
                verts.Add(map.surfedgesLump[i] > 0 ?
                          map.vertexesLump[map.edgesLump[Mathf.Abs(map.surfedgesLump[i])][0]] :
                          map.vertexesLump[map.edgesLump[Mathf.Abs(map.surfedgesLump[i])][1]]);
            }

            for (int i = 1; i < verts.Count - 1; i++)
            {
                tris.Add(0);
                tris.Add(i);
                tris.Add(i + 1);
            }

            bsptexinfo texInfo = map.texinfosLump [map.facesLump [index].texinfo];

            float scales = map.texdataLump[texInfo.texdata].width * uSrcSettings.Inst.worldScale;
            float scalet = map.texdataLump[texInfo.texdata].height * uSrcSettings.Inst.worldScale;

            for (int i = 0; i < verts.Count; i++)
            {
                float tU = Vector3.Dot(verts[i] * uSrcSettings.Inst.worldScale, texInfo.texvecs) + (texInfo.texoffs * uSrcSettings.Inst.worldScale);
                float tV = Vector3.Dot(verts[i] * uSrcSettings.Inst.worldScale, texInfo.texvect) + (texInfo.texofft * uSrcSettings.Inst.worldScale);
                UVs.Add(new Vector2(tU / scales, tV / scalet));
            }

            int lightmapW = (map.facesLump[index].LightmapTextureSizeInLuxels[0] + 1);
            int lightmapH = (map.facesLump[index].LightmapTextureSizeInLuxels[1] + 1);

            for (int i = 0; i < verts.Count; i++)
            {
                float U = Vector3.Dot(verts[i], texInfo.lightvecs) + texInfo.lightoffs + 0.5f - map.facesLump[index].LightmapTextureMinsInLuxels[0];
                float V = Vector3.Dot(verts[i], texInfo.lightvect) + texInfo.lightofft + 0.5f - map.facesLump[index].LightmapTextureMinsInLuxels[1];
                //U=(U*(float)((float)lightmapW/((float)lightmapW+2f)))+(1f/((float)lightmapW+2f));
                //V=(V*(float)((float)lightmapH/((float)lightmapH+2f)))+(1f/((float)lightmapH+2f));
                UV2s.Add(new Vector2(U / (lightmapW), V / (lightmapH)));
            }

            for (int i = 0; i < verts.Count; i++)
            {
                verts[i] *= uSrcSettings.Inst.worldScale;
            }

            int texID = map.texdataLump [map.texinfosLump [map.facesLump [index].texinfo].texdata].nameStringTableID;

            face f = new face();

            f.lightMapW = lightmapW;
            f.lightMapH = lightmapH;
            f.points    = verts.ToArray();
            f.triangles = tris.ToArray();
            f.uv        = UVs.ToArray();
            f.uv2       = UV2s.ToArray();
            f.flags     = flags;
            f.index     = index;
            f.texID     = texID;

            return(f);
        }
        public Mesh Unfold(Mesh mesh)
        {
            List<face> Faces = new List<face>();
            List<edge> Edges = new List<edge>();

            mesh.Faces.ConvertQuadsToTriangles();
            mesh.UnifyNormals();
            mesh.Compact();
            Rhino.Geometry.Collections.MeshTopologyEdgeList el = mesh.TopologyEdges;
            Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices;
            mesh.FaceNormals.ComputeFaceNormals();
            //Print(mesh.FaceNormals.Count.ToString());
            //  Print(mesh.Vertices.Count.ToString());
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                face f1 = new face(
                  new Point3d(mesh.Vertices[mesh.Faces[i].A]),
                  new Point3d(mesh.Vertices[mesh.Faces[i].B]),
                  new Point3d(mesh.Vertices[mesh.Faces[i].C]),
                  mesh.FaceNormals[i]
                  );

                Faces.Add(f1);
            }
            for (int i = 0; i < el.Count; i++)
            {
                int[] faceid = el.GetConnectedFaces(i);

                edge e1 = new edge(vs[el.GetTopologyVertices(i).I], vs[el.GetTopologyVertices(i).J]);
                if (faceid.Length == 1)
                {
                    e1.Faces = new face[1];
                    e1.Faces[0] = Faces[faceid[0]];
                }
                else if (faceid.Length > 1)
                {
                    e1.Faces = new face[2];
                    e1.Faces[0] = Faces[faceid[0]];
                    e1.Faces[1] = Faces[faceid[1]];
                }
                e1.ID = i;
                Edges.Add(e1);
            }
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                int[] edgeid = el.GetEdgesForFace(i);
                face f1 = Faces[i];
                f1.edges[0] = Edges[edgeid[0]];
                f1.edges[1] = Edges[edgeid[1]];
                f1.edges[2] = Edges[edgeid[2]];
                f1.ID = i;
            }

            /* List<  Mesh> output2 = new List<  Mesh>();
             for (int i = 0; i < Faces.Count; i++)
             {
               output2.Add(Faces[i].DrawFace());
             }
             B = output2;
             */
            face f = Faces[0];
            f.AddTransform(Transform.PlaneToPlane(new Plane(f.Center(), f.Normal), Plane.WorldXY));

            FaceLoop(f);
            //Print(f.Pts[0].X.ToString() + "/" + f.Pts[0].Y.ToString() + "/" + f.Pts[0].Z.ToString());
            Mesh output = new Mesh();
            for (int i = 0; i < Faces.Count; i++)
            {
                output.Append(Faces[i].DrawFace());
            }
            return output;
        }
    private static void CreateModel(int index)
    {
        Dictionary <int, List <int> > subMeshData = new Dictionary <int, List <int> >();
        GameObject model = new GameObject("*" + index);

        model.transform.parent = BSP_WorldSpawn.transform;

        int firstFace = BSP_Models[index].firstface;
        int faces     = BSP_Models[index].numfaces;

        for (int i = firstFace; i < firstFace + faces; i++)
        {
            if (!subMeshData.ContainsKey(BSP_Texdata[BSP_Texinfo[BSP_Faces[i].texinfo].texdata].nameStringTableID))
            {
                subMeshData.Add(BSP_Texdata[BSP_Texinfo[BSP_Faces[i].texinfo].texdata].nameStringTableID, new List <int>());
            }

            subMeshData[BSP_Texdata[BSP_Texinfo[BSP_Faces[i].texinfo].texdata].nameStringTableID].Add(i);
        }

        for (int i = 0; i < BSP_TexStrData.Count; i++)
        {
            if (!subMeshData.ContainsKey(i))
            {
                continue;
            }

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector2> uv        = new List <Vector2>();
            List <int>     triangles = new List <int>();
            List <face>    faceList  = new List <face>();

            for (int k = 0; k < subMeshData[i].Count; k++)
            {
                // Get points, indices, UV's
                if (BSP_Faces[subMeshData[i][k]].dispinfo == -1)
                {
                    face f           = CreateFace(subMeshData[i][k]);
                    int  pointOffset = vertices.Count;

                    for (int j = 0; j < f.triangles.Length; j++)
                    {
                        triangles.Add(f.triangles[j] + pointOffset);
                    }

                    vertices.AddRange(f.points);
                    uv.AddRange(f.uv);
                    faceList.Add(f);
                }
            }

            GameObject submesh = new GameObject(BSP_TexStrData[i]);
            submesh.transform.parent = model.transform;

            MeshRenderer meshRenderer = submesh.AddComponent <MeshRenderer>();
            MeshFilter   meshFilter   = submesh.AddComponent <MeshFilter>();

            List <Vector2> uv2      = new List <Vector2>();
            Texture2D      lightMap = new Texture2D(0, 0);

            // Load lightmaps and generate atlas
            CreateLightMap(faceList, ref lightMap, ref uv2);

            WorldController.CurrentTexPath = WorldController.DefaultTexPath;
            if (BSP_TexStrData[i].Contains(WorldController.MapName))
            {
                WorldController.CurrentTexPath = WorldController.PakTexPath;
            }

            // Load material for this object
            meshRenderer.sharedMaterial = ValveTextureLoader.LoadMaterial(BSP_TexStrData[i]);
            meshRenderer.sharedMaterial.SetTexture("_LightMap", lightMap);

            if (BSP_TexStrData[i].Contains("TOOLS/"))
            {
                meshRenderer.enabled = false;
            }

            // Generate submesh
            meshFilter.sharedMesh           = new Mesh();
            meshFilter.sharedMesh.vertices  = vertices.ToArray();
            meshFilter.sharedMesh.triangles = triangles.ToArray();

            meshFilter.sharedMesh.uv  = uv.ToArray();
            meshFilter.sharedMesh.uv2 = uv2.ToArray();

            meshFilter.sharedMesh.RecalculateNormals();
            meshFilter.sharedMesh.Optimize();
        }
    }
    private static void CreateDispSurface()
    {
        GameObject BSP_DispSurface = new GameObject(WorldController.MapName + "_disp");
        Dictionary <int, List <int> > subMeshData = new Dictionary <int, List <int> >();

        for (int i = 0; i < BSP_Faces.Count; i++)
        {
            if (!subMeshData.ContainsKey(BSP_Texdata[BSP_Texinfo[BSP_Faces[i].texinfo].texdata].nameStringTableID))
            {
                subMeshData.Add(BSP_Texdata[BSP_Texinfo[BSP_Faces[i].texinfo].texdata].nameStringTableID, new List <int>());
            }

            subMeshData[BSP_Texdata[BSP_Texinfo[BSP_Faces[i].texinfo].texdata].nameStringTableID].Add(i);
        }

        for (int i = 0; i < BSP_TexStrData.Count; i++)
        {
            if (!subMeshData.ContainsKey(i))
            {
                continue;
            }

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector2> uv        = new List <Vector2>();
            List <int>     triangles = new List <int>();

            for (int k = 0; k < subMeshData[i].Count; k++)
            {
                if (BSP_Faces[subMeshData[i][k]].dispinfo != -1)
                {
                    face f           = CreateDispSurface(BSP_Faces[subMeshData[i][k]].dispinfo);
                    int  pointOffset = vertices.Count;

                    for (int j = 0; j < f.triangles.Length; j++)
                    {
                        triangles.Add(f.triangles[j] + pointOffset);
                    }

                    vertices.AddRange(f.points);
                    uv.AddRange(f.uv);
                }
            }

            if (vertices.Count > 0)
            {
                GameObject submesh = new GameObject(BSP_TexStrData[i]);
                submesh.transform.localScale = new Vector3(1, 1, -1);
                submesh.transform.parent     = BSP_DispSurface.transform;

                MeshRenderer meshRenderer = submesh.AddComponent <MeshRenderer>();
                MeshFilter   meshFilter   = submesh.AddComponent <MeshFilter>();

                WorldController.CurrentTexPath = WorldController.DefaultTexPath;
                if (BSP_TexStrData[i].Contains(WorldController.MapName))
                {
                    WorldController.CurrentTexPath = WorldController.PakTexPath;
                }

                meshRenderer.sharedMaterial = ValveTextureLoader.LoadMaterial(BSP_TexStrData[i]);

                meshFilter.sharedMesh           = new Mesh();
                meshFilter.sharedMesh.vertices  = vertices.ToArray();
                meshFilter.sharedMesh.triangles = triangles.ToArray();
                meshFilter.sharedMesh.uv        = uv.ToArray();

                meshFilter.sharedMesh.RecalculateNormals();
                meshFilter.sharedMesh.Optimize();
            }
        }
    }
Beispiel #25
0
 public Snack()
 {
     Position t = new Position(55); footPrint[0] = t; dirc = face.up;
 }
Beispiel #26
0
        public static List <face> iterate(List <face> face_list)
        {
            UnityEngine.Debug.Log("Running iterate function");
            if (face_list.Count <= 0)
            {
                // return an empty list if face_list provided is empty
                return(new List <face>());
            }
            // select a single element from the active face list
            face face_element = face_list[0];

            // if the selected face has conflicts, initate search for the horizon
            if (face_element.Conflict_List.Count >= 1)
            {
                // We select the furthest point from the face (found by accessing the face's sorted List)
                Vector3 furthest_from_face = face_element.Conflict_List.OrderByDescending(element => Distance_from_Plane(face_element.corners[0], face_element.corners[2] - face_element.corners[0], face_element.corners[1] - face_element.corners[0], element, false)).First();
                // Flood search based off what this furthest point can see
                var         horizon_edge_list = new Stack <edge>();
                var         current_face      = face_element;
                var         visited_faces     = new Stack <face>();
                string      path           = "";
                List <face> daughter_faces = new List <face>();
                // Use a Flood Fill algorithm to search for horizon edges
                path = Flood_Fill_and_Make(furthest_from_face, current_face, horizon_edge_list, visited_faces, daughter_faces);
                // Check for any obvious error in the results of the flood search
                UnityEngine.Debug.Log("Flooded, entering main debugging area");
                UnityEngine.Debug.Log("Flood path: " + path);
                UnityEngine.Debug.Log("Number of Horizons found: " + horizon_edge_list.Count);
                UnityEngine.Debug.Log("Number of visible faces: " + visited_faces.Count);
                UnityEngine.Debug.Log("Number of daughter: " + daughter_faces.Count);
                if (visited_faces.Count == 0)
                {
                    UnityEngine.Debug.Log("ERROR: current point assigned to wrong face");
                    face_element.hidden = true;
                    return(face_list);
                }
                if (horizon_edge_list.Count < 3)
                {
                    UnityEngine.Debug.Log("ERROR: improper flood");
                    face_element.hidden = true;
                    return(face_list);
                }

                // Make and link edges that exsist inbetween the newly formed faces
                var new_edges = new List <edge>();
                foreach (face f1 in daughter_faces)
                {
                    foreach (face f2 in daughter_faces)
                    {
                        if (f1 != f2)
                        {
                            foreach (Vector3 c1A in f1.corners)
                            {
                                foreach (Vector3 c1B in f1.corners)
                                {
                                    if (c1A != c1B)
                                    {
                                        if (f2.corners.Contains(c1A) && f2.corners.Contains(c1B))
                                        {
                                            bool unique = true;
                                            foreach (edge e in horizon_edge_list)
                                            {
                                                unique = unique && !(e.vertices.Contains(c1A) && e.vertices.Contains(c1B));
                                            }
                                            foreach (edge e in new_edges)
                                            {
                                                unique = unique && !(e.vertices.Contains(c1A) && e.vertices.Contains(c1B));
                                            }
                                            if (unique)
                                            {
                                                var new_edge = new edge(c1A, c1B);
                                                new_edge.Connect_to_Face(f1);
                                                new_edge.Connect_to_Face(f2);
                                                new_edges.Add(new_edge);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                UnityEngine.Debug.Log("new edge count: " + new_edges.Count);

                // Checking that all new faces are connected to 3 other faces (like triangles should)
                foreach (face f in daughter_faces)
                {
                    if (f.edges.Count != 3)
                    {
                        UnityEngine.Debug.Log("ERROR: daughter face isn't connected to 3 other faces");
                        UnityEngine.Debug.Log(f.edges.Count);
                        f.hidden = true;
                        return(face_list);
                    }
                }

                // Marking all hidden faces as such for clean up later
                face[] hidden_faces = visited_faces.ToArray();
                foreach (face f in hidden_faces)
                {
                    f.hidden = true;
                }

                // Combine the conflict list of obsolete hidden faces
                Vector3[] compound_conflict_list = (from face in hidden_faces from point in face.Conflict_List select point).ToArray();
                UnityEngine.Debug.Log(compound_conflict_list.Length);

                // Remove points which are now hidden by the new faces
                foreach (face f in hidden_faces)
                {
                    compound_conflict_list = Clear_Simplex_Volume(compound_conflict_list, new Vector3[] { f.corners[0], f.corners[1], f.corners[2], furthest_from_face }).ToArray();
                }
                var remaining_conflicts = compound_conflict_list;
                UnityEngine.Debug.Log(remaining_conflicts.Length);

                // Redistribute conflicts between the new faces
                Distribute_Conflicts(remaining_conflicts, daughter_faces);

                // Check if new faces are complete (and mark them as such if so) and finally add them to the face list
                foreach (face daughter in daughter_faces)
                {
                    if (daughter.Conflict_List.Count <= 0)
                    {
                        daughter.complete = true;
                    }
                    face_list.Add(daughter);
                }
            }
            else
            {
                // else, face is complete and should be marked as such
                UnityEngine.Debug.Log("Empty conflict list");
                face_element.complete = true;
            }
            return(face_list);
        }
Beispiel #27
0
        public Mesh Unfold(Mesh mesh)
        {
            List <face> Faces = new List <face>();
            List <edge> Edges = new List <edge>();

            mesh.Faces.ConvertQuadsToTriangles();
            mesh.UnifyNormals();
            mesh.Compact();
            Rhino.Geometry.Collections.MeshTopologyEdgeList   el = mesh.TopologyEdges;
            Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices;
            mesh.FaceNormals.ComputeFaceNormals();
            //Print(mesh.FaceNormals.Count.ToString());
            //  Print(mesh.Vertices.Count.ToString());
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                face f1 = new face(
                    new Point3d(mesh.Vertices[mesh.Faces[i].A]),
                    new Point3d(mesh.Vertices[mesh.Faces[i].B]),
                    new Point3d(mesh.Vertices[mesh.Faces[i].C]),
                    mesh.FaceNormals[i]
                    );

                Faces.Add(f1);
            }
            for (int i = 0; i < el.Count; i++)
            {
                int[] faceid = el.GetConnectedFaces(i);

                edge e1 = new edge(vs[el.GetTopologyVertices(i).I], vs[el.GetTopologyVertices(i).J]);
                if (faceid.Length == 1)
                {
                    e1.Faces    = new face[1];
                    e1.Faces[0] = Faces[faceid[0]];
                }
                else if (faceid.Length > 1)
                {
                    e1.Faces    = new face[2];
                    e1.Faces[0] = Faces[faceid[0]];
                    e1.Faces[1] = Faces[faceid[1]];
                }
                e1.ID = i;
                Edges.Add(e1);
            }
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                int[] edgeid = el.GetEdgesForFace(i);
                face  f1     = Faces[i];
                f1.edges[0] = Edges[edgeid[0]];
                f1.edges[1] = Edges[edgeid[1]];
                f1.edges[2] = Edges[edgeid[2]];
                f1.ID       = i;
            }


            /* List<  Mesh> output2 = new List<  Mesh>();
             * for (int i = 0; i < Faces.Count; i++)
             * {
             * output2.Add(Faces[i].DrawFace());
             * }
             * B = output2;
             */
            face f = Faces[0];

            f.AddTransform(Transform.PlaneToPlane(new Plane(f.Center(), -f.Normal), Plane.WorldXY));

            FaceLoop(f);
            //Print(f.Pts[0].X.ToString() + "/" + f.Pts[0].Y.ToString() + "/" + f.Pts[0].Z.ToString());
            Mesh output = new Mesh();

            for (int i = 0; i < Faces.Count; i++)
            {
                output.Append(Faces[i].DrawFace());
            }
            return(output);
        }
Beispiel #28
0
 foreach (var(face, numericValue) in faces)
Beispiel #29
0
        void GenerateDispFaceObject(int index, int model)
        {
            face f = BuildDispFace(index, model, map.facesLump[index].dispinfo);

            GameObject faceObject = new GameObject("DispFace: " + f.index);

            MeshRenderer mr = faceObject.AddComponent <MeshRenderer>();

            //Material mat;
            MeshFilter mf = faceObject.AddComponent <MeshFilter>();

            mf.mesh           = new Mesh();
            mf.mesh.name      = "DispFace " + f.index;
            mf.mesh.vertices  = f.points;
            mf.mesh.triangles = f.triangles;
            mf.mesh.uv        = f.uv;

            if (uSrcSettings.Inst.textures)
            {
                bsptexdata curTexData = map.texdataLump[map.texinfosLump[map.facesLump[index].texinfo].texdata];

                //===========================Material=============================
                string materialName = "";
                //VMTLoader.VMTFile vmtFile=null;
                //Material tempmat=null;

                //string
                if (map.texdataStringDataLump.Length > map.texdataStringTableLump [curTexData.nameStringTableID] + 92)
                {
                    materialName = new string (map.texdataStringDataLump, map.texdataStringTableLump [curTexData.nameStringTableID], 92);
                }
                else
                {
                    materialName = new string (map.texdataStringDataLump, map.texdataStringTableLump [curTexData.nameStringTableID], map.texdataStringDataLump.Length - map.texdataStringTableLump [curTexData.nameStringTableID]);
                }

                materialName = materialName.ToLower();

                if (materialName.Contains("\0"))
                {
                    materialName = materialName.Remove(materialName.IndexOf('\0'));
                }

                Material tempmat = ResourceManager.Inst.GetMaterial(materialName);
                //=================Material End========================

                mr.material = tempmat;
            }
            else
            {
                mr.material = Test.Inst.testMaterial;
            }

            mf.mesh.RecalculateNormals();

            faceObject.transform.parent = dispObject.transform;
            mf.mesh.Optimize();
            faceObject.isStatic = true;

            if (uSrcSettings.Inst.genColliders)
            {
                faceObject.AddComponent <MeshCollider>();
            }
        }
Beispiel #30
0
 public static void  setdirc(face a)
 {
     dirc = a;
 }
     DrawFace(face)
 Next
 public void FaceLoop(face f)
 {
     if (f.ID != -1)
     {
         ///////////
         // Print("00000002");
         f.ID = -1; f.Fold();
         for (int i = 0; i < f.edges.Length; i++)
         {
             edge e = f.edges[i];
             if (e.ID != -1)
             {
                 e.ID = -1;
                 if (e.Faces.Length == 2)
                 {
                     face f2;
                     if (f.EqualTo(e.Faces[0])) { f2 = e.Faces[1]; } else { f2 = e.Faces[0]; }
                     if (f2.ID != -1)
                     {
                         //Print(f2.ID.ToString());
                         f2.AddTransform(f.Xform);
                         f2.AddTransform(e.fold(f2, e, f));
                         FaceLoop(f2);
                     }
                 }
             }
         }
         //////
     }
 }
Beispiel #33
0
        public Bitmap drawCube(Point4D[] orgV, Point4D[] newV, float dist, face[] faces, float angle, Bitmap bmp, Color[] colors)
        {
            Bitmap bmpt = bmp;
            //graphics.Clear(Color.Black);
            float fi = angle; //120
            float d  = dist;
            float sx = pictureBox1.Width;
            float sy = pictureBox1.Height;

            Matrix3D Ry = new Matrix3D(Math.Cos(alfa), 0, -Math.Sin(alfa), 0,
                                       0, 1, 0, 0,
                                       Math.Sin(alfa), 0, Math.Cos(alfa), 0,
                                       0, 0, 0, 1);

            Matrix3D Rx = new Matrix3D(1, 0, 0, 0,
                                       0, Math.Cos(beta), Math.Sin(beta), 0,
                                       0, -Math.Sin(beta), Math.Cos(beta), 0,
                                       0, 0, 0, 1);

            Matrix3D T = new Matrix3D(1, 0, 0, 0,
                                      0, 1, 0, 0,
                                      0, 0, 1, 0,
                                      0, 0, d, 1);   //model, transformation matrix

            Matrix3D P = new Matrix3D(sx / (2 * Math.Tan(fi / 2)), 0, 0, 0,
                                      0, -sx / (2 * Math.Tan(fi / 2)), 0, 0,
                                      -sx / 2, -sy / 2, 0, -1,
                                      0, 0, -1, 0);   //perspective projection matrix

            for (int i = 0; i < 8; i++)
            {
                Point4D p = orgV[i];

                Point4D s = Point4D.Multiply(p, Ry);
                Point4D q = Point4D.Multiply(s, Rx);
                Point4D r = Point4D.Multiply(q, T);
                Point4D w = Point4D.Multiply(r, P);

                w.X /= w.W;
                w.Y /= w.W;
                w.Z /= w.W;
                w.W /= w.W;

                newV[i] = w;
            }

            //for (int i = 0; i < 4; i++)
            //{
            //    graphics.DrawLine(pen, (float)(newV[i].X), (float)(newV[i].Y), (float)(newV[(i + 1) % 4].X), (float)(newV[(i + 1) % 4].Y));
            //    graphics.DrawLine(pen, (float)(newV[i + 4].X), (float)(newV[i + 4].Y), (float)(newV[(i + 1) % 4 + 4].X), (float)(newV[(i + 1) % 4 + 4].Y));
            //    graphics.DrawLine(pen, (float)(newV[i].X), (float)(newV[i].Y), (float)(newV[(i + 1) % 4 + 4].X), (float)(newV[(i + 1) % 4 + 4].Y));
            //}

            faces[0] = new face(newV[0], newV[1], newV[2], newV[3], new Point4D(0, -1, 0, 1), colors[0]);
            faces[1] = new face(newV[0], newV[1], newV[6], newV[5], new Point4D(0, 0, 1, 1), colors[1]);
            faces[2] = new face(newV[1], newV[2], newV[7], newV[6], new Point4D(1, 0, 0, 1), colors[2]);
            faces[3] = new face(newV[2], newV[3], newV[4], newV[7], new Point4D(0, 0, -1, 1), colors[3]);
            faces[4] = new face(newV[0], newV[3], newV[4], newV[5], new Point4D(-1, 0, 0, 1), colors[4]);
            faces[5] = new face(newV[4], newV[5], newV[6], newV[7], new Point4D(0, 1, 0, 1), colors[5]);

            for (int i = 0; i < 6; i++)
            {
                bmpt = fillPolygon(faces[i].vertices.ToList(), faces[i].color, bmpt);
            }
            return(bmpt);
        }