コード例 #1
0
ファイル: VBO.cs プロジェクト: YourWishes/FaultEnginev3
        public void generateVBO()
        {
            lock (model) {
                List <Vertice>           verts = model.getAllVertices();
                List <TextureCoordinate> tcors = model.getAllTextureCoordinates();

                this.vSize = verts.Count;
                this.tSize = tcors.Count;

                if (this.vSize < 1)
                {
                    return;
                }

                float[] vertices = new float[this.vSize * 3];
                for (int i = 0; i < this.vSize; i++)
                {
                    Vertice v = verts[i];
                    int     j = i * 3;
                    vertices[j + 0] = (float)v.getX();
                    vertices[j + 1] = (float)v.getY();
                    vertices[j + 2] = (float)v.getZ();
                }

                float[] coords = new float[this.tSize * 2];
                for (int i = 0; i < this.tSize; i++)
                {
                    TextureCoordinate t = tcors[i];
                    int j = i * 2;
                    coords[j + 0] = (float)t.getX();
                    coords[j + 1] = (float)t.getY();
                }

                this.vb = new VertexBuffer(this.vSize, VertexFormat.Float3, VertexFormat.Float2);
                lock (this.vb) {
                    this.vb.SetVertices(0, vertices);
                    if (this.vSize == this.tSize)
                    {
                        this.vb.SetVertices(1, coords);
                    }
                }
            }
        }
コード例 #2
0
 public Location(Vertice v) : this(v.getX(), v.getY(), v.getZ())
 {
 }
コード例 #3
0
        public override List <Model> loadModels(string data)
        {
            String[] lines = removeBlankElements(data.Replace("\r", "\n").Split('\n'));

            List <Model> models = new List <Model>();
            Model        m      = null;
            Model        g      = null;

            List <Material> materials = new List <Material>();

            List <Vertice>           loadedVertices      = new List <Vertice>();
            List <TextureCoordinate> loadedTextureCoords = new List <TextureCoordinate>();
            List <Material>          loadedMaterials     = new List <Material>();

            for (int i = 0; i < lines.Length; i++)
            {
                String line = lines[i];

                BAD_ID = i;

                if (line.StartsWith("ml"))
                {
                    line = getLine(line, "ml");
                    if (m == null)
                    {
                        continue;
                    }
                    Location location = Location.ValueOf(line);
                    m.getLocation().set(location);
                    continue;
                }

                if (line.StartsWith("o"))
                {
                    line = getLine(line, "o");
                    m    = new Model();
                    m.setName(line);
                    models.Add(m);
                    g = null;
                    continue;
                }

                if (line.StartsWith("usemtl"))
                {
                    line = getLine(line, "usemtl");
                    Material guess = null;
                    foreach (Material mat in materials)
                    {
                        if (mat.getName() != null && mat.getName().Equals(line))
                        {
                            guess = mat;
                            break;
                        }
                    }
                    if (guess == null)
                    {
                        guess = new Material();
                        guess.setName(line);
                        materials.Add(guess);
                    }
                    m.setMaterial(guess);
                }

                if (line.StartsWith("s"))
                {
                    line = getLine(line, "s");
                    if (g == null)
                    {
                        g = new Model();
                        models.Add(g);
                    }
                    Material mat = g.getMaterial();
                    m = new Model();
                    m.setMaterial(mat);
                    g.addChild(m);
                    continue;
                }

                if (line.StartsWith("g"))
                {
                    line = getLine(line, "g");
                    g    = new Model();
                    models.Add(g);
                    m = g;
                    continue;
                }

                if (line.StartsWith("mtllib"))
                {
                    continue;
                }

                if (line.StartsWith("usemtl"))
                {
                    continue;
                }

                if (line.StartsWith("vt"))
                {
                    line = getLine(line, "vt");
                    String[]          coords = removeBlankElements(line.Split(' '));
                    TextureCoordinate tc     = new TextureCoordinate(Convert.ToDouble(coords[0]), Convert.ToDouble(coords[1]));
                    loadedTextureCoords.Add(tc);
                    continue;
                }

                if (line.StartsWith("vn"))
                {
                    continue;
                }

                if (line.StartsWith("v"))
                {
                    line = getLine(line, "v");
                    String[] coordinates = removeBlankElements(line.Split(' '));
                    Vertice  v           = new Vertice();
                    v.set(Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[2]));
                    loadedVertices.Add(v);
                    continue;
                }

                if (line.StartsWith("f"))
                {
                    line = getLine(line, "f");
                    String[] vertIndexs = removeBlankElements(line.Split(' '));

                    if (m == null)
                    {
                        m = new Model();
                        models.Add(m);
                    }

                    List <Vertice>           selectedVertices           = new List <Vertice>();
                    List <TextureCoordinate> selectedTextureCoordinates = new List <TextureCoordinate>();

                    for (int index = 0; index < vertIndexs.Length; index++)
                    {
                        String indexLine = vertIndexs[index];

                        Vertice           selectedVertice           = null;
                        TextureCoordinate selectedTextureCoordinate = null;

                        if (indexLine.Contains("//"))
                        {
                            //Form of v1//vn1
                            String[] parts = indexLine.Split(new String[] { "//" }, StringSplitOptions.RemoveEmptyEntries);
                            selectedVertice = loadedVertices[Convert.ToInt32(parts[0]) - 1];
                        }
                        else if (indexLine.Contains("/"))
                        {
                            String[] requesting = indexLine.Split('/');

                            if (requesting.Length == 2)
                            {
                                //Form of v1/vt1
                                selectedVertice           = loadedVertices[Convert.ToInt32(requesting[0]) - 1];
                                selectedTextureCoordinate = loadedTextureCoords[Convert.ToInt32(requesting[1]) - 1];
                            }
                            else if (requesting.Length == 3)
                            {
                                //Form of v1/vt1/vn1
                                selectedVertice           = loadedVertices[Convert.ToInt32(requesting[0]) - 1];
                                selectedTextureCoordinate = loadedTextureCoords[Convert.ToInt32(requesting[1]) - 1];
                            }
                        }
                        else
                        {
                            //PURE VERTICE GETTING
                            selectedVertice = loadedVertices[Convert.ToInt32(indexLine) - 1];
                        }

                        //Now to add these things to the face
                        if (selectedVertice != null)
                        {
                            selectedVertices.Add(selectedVertice);
                        }
                        if (selectedTextureCoordinate != null)
                        {
                            selectedTextureCoordinates.Add(selectedTextureCoordinate);
                        }
                    }

                    //Create a Face
                    if (selectedVertices.Count == 3)
                    {
                        //This is a triangle (yay)
                        Face f = new Face();
                        for (int index = 0; index < selectedVertices.Count; index++)
                        {
                            try { f.addVertice(selectedVertices[index]); }catch (Exception t) {}
                            try { f.addTextureCoordinate(selectedTextureCoordinates[index]); }catch (Exception t) {}
                        }
                        m.addFace(f);
                    }
                    else if (selectedVertices.Count == 4)
                    {
                        //Convert to Triangle and add
                        Quad quad = new Quad();

                        quad.setVert0(selectedVertices[0]);
                        quad.setVert1(selectedVertices[1]);
                        quad.setVert2(selectedVertices[2]);
                        quad.setVert3(selectedVertices[3]);

                        try { quad.setTextureCoordinate0(selectedTextureCoordinates[0]); }catch (Exception t) {}
                        try { quad.setTextureCoordinate1(selectedTextureCoordinates[1]); }catch (Exception t) {}
                        try { quad.setTextureCoordinate2(selectedTextureCoordinates[2]); }catch (Exception t) {}
                        try { quad.setTextureCoordinate3(selectedTextureCoordinates[3]); }catch (Exception t) {}

                        m.addFaces(quad.toQuadArray());
                    }
                    else
                    {
                        //Something that isn't a quad or a triangle?
                    }
                }
            }

            //Logging
            Game.GAME_INSTANCE.getLogger().log("Model loaded.");
            return(models);
        }
コード例 #4
0
ファイル: Vertice.cs プロジェクト: YourWishes/FaultEnginev3
 public Vertice(Vertice v) : this()
 {
     this.x = v.x;
     this.y = v.y;
     this.z = v.z;
 }
コード例 #5
0
ファイル: Face.cs プロジェクト: YourWishes/FaultEnginev3
 public void removeVertice(Vertice v)
 {
     this.vertices.Remove(v);
 }
コード例 #6
0
        public void updateFace()
        {
            Vertice topLeft     = new Vertice(0, 0, 0);
            Vertice topRight    = new Vertice(this.width, 0, 0);
            Vertice bottomLeft  = new Vertice(0, this.height, 0);
            Vertice bottomRight = new Vertice(this.width, this.height, 0);

            int lx = 0;
            int ly = 0;
            int mx = 1;
            int my = 1;

            if (this.xf)
            {
                lx = 1;
                mx = 0;
            }

            if (this.yf)
            {
                ly = 1;
                my = 0;
            }

            TextureCoordinate topLeftTC     = new TextureCoordinate(lx, ly);
            TextureCoordinate topRightTC    = new TextureCoordinate(mx, ly);
            TextureCoordinate bottomLeftTC  = new TextureCoordinate(lx, my);
            TextureCoordinate bottomRightTC = new TextureCoordinate(mx, my);

            Face topLeftFace = new Face();

            topLeftFace.addVertice(bottomLeft);
            topLeftFace.addVertice(topRight);
            topLeftFace.addVertice(topLeft);

            topLeftFace.addTextureCoordinate(bottomLeftTC);
            topLeftFace.addTextureCoordinate(topRightTC);
            topLeftFace.addTextureCoordinate(topLeftTC);

            Face topRightFace = new Face();

            topRightFace.addVertice(bottomRight);
            topRightFace.addVertice(topRight);
            topRightFace.addVertice(bottomLeft);

            topLeftFace.addTextureCoordinate(bottomRightTC);
            topLeftFace.addTextureCoordinate(topRightTC);
            topLeftFace.addTextureCoordinate(bottomLeftTC);

            foreach (Face f in this.getFaces())
            {
                this.removeFace(f);
            }

            addFace(topLeftFace);
            addFace(topRightFace);

            if (Thread.CurrentThread != Game.GAME_INSTANCE.getMainThread())
            {
                if (this.getVBO() != null)
                {
                    lock (this.getVBO()) { this.getVBO().Dispose(); }
                }
                this.setVBO(null);
                this.addToVBOList();
                while (!this.isOnVBO())
                {
                    continue;
                }
            }
            else
            {
                if (this.getVBO() != null)
                {
                    this.getVBO().Dispose();
                }
                this.newVBO();
            }
        }
コード例 #7
0
ファイル: Quad.cs プロジェクト: YourWishes/FaultEnginev3
 public void setVert3(Vertice v)
 {
     topRight.setVert2(v);
 }
コード例 #8
0
ファイル: Face.cs プロジェクト: YourWishes/FaultEnginev3
 public void addVertice(Vertice v)
 {
     lock (this.vertices) { this.vertices.Add(v); }
 }
コード例 #9
0
ファイル: Quad.cs プロジェクト: YourWishes/FaultEnginev3
 public void setVert2(Vertice v)
 {
     bottomLeft.setVert2(v); topRight.setVert1(v);
 }
コード例 #10
0
ファイル: Quad.cs プロジェクト: YourWishes/FaultEnginev3
 public void setVert1(Vertice v)
 {
     bottomLeft.setVert1(v);
 }
コード例 #11
0
ファイル: Triangle.cs プロジェクト: YourWishes/FaultEnginev3
 public void setVert2(Vertice v)
 {
     this.v2 = v;
     this.reset();
 }
コード例 #12
0
ファイル: Triangle.cs プロジェクト: YourWishes/FaultEnginev3
 public void setVert1(Vertice v)
 {
     this.v1 = v;
     this.reset();
 }
コード例 #13
0
ファイル: Triangle.cs プロジェクト: YourWishes/FaultEnginev3
 public void setVert0(Vertice v)
 {
     this.v0 = v;
     this.reset();
 }