// Use this for initialization
 void Start()
 {
     shape           = FunctionsRepository.Shape.Custom;
     scale           = 0.1f;
     resolution      = 100;
     this.vertexMesh = new VertexMesh(this, shape, scale, resolution);
 }
Exemple #2
0
        private void AddNewVertex(int vertexID,
                                  int normalID,
                                  Dictionary <long, ushort> generatedVertices,
                                  List <MS3Vertex> sourceVertices,
                                  List <MS3Normal> sourceNormals,
                                  List <VertexMesh> vertices,
                                  List <ushort> indices,
                                  int indiceOffset,
                                  int TextureArrayIndex)
        {
            long ID = (((Int64)(normalID) << 32) + (vertexID << 16) + TextureArrayIndex);

            ushort vertexIndice;

            if (!generatedVertices.TryGetValue(ID, out vertexIndice))
            {
                //Not existing, create it.
                VertexMesh vertex = new VertexMesh()
                {
                    Normal            = new Vector3(sourceNormals[normalID].X, sourceNormals[normalID].Y, sourceNormals[normalID].Z),
                    Position          = new Vector3(sourceVertices[vertexID].X, sourceVertices[vertexID].Y, sourceVertices[vertexID].Z),
                    TextureCoordinate = new Vector3(sourceVertices[vertexID].U, sourceVertices[vertexID].V, TextureArrayIndex)
                };
                vertices.Add(vertex);
                vertexIndice = (ushort)(vertices.Count - 1);
                generatedVertices.Add(ID, vertexIndice);
            }
            indices.Add((ushort)(vertexIndice + indiceOffset));
        }
Exemple #3
0
        void BuildTileMap()
        {
            Vector3[] Verticies = new Vector3[Tile_Width * Tile_Height * 4];
            Vector2[] UVs       = new Vector2[Verticies.Length];

            for (int x = 0; x < Tile_Width; x++)
            {
                for (int y = 0; y < Tile_Height; y++)
                {
                    int TileIndex = TileMap[x, y];

                    int TexU = TileIndex % (TextureSize / TextureSize);
                    int TexV = TileIndex / (TextureSize / TextureSize);

                    ArraySegment <Vector3> Quad = new ArraySegment <Vector3>(Verticies, (x + y * Tile_Width) * 4, 4);
                    Quad[0] = new Vector3(x * TextureSize, y * TextureSize, 0);
                    Quad[1] = new Vector3((x + 1) * TextureSize, y * TextureSize, 0);
                    Quad[2] = new Vector3((x + 1) * TextureSize, (y + 1) * TextureSize, 0);
                    Quad[3] = new Vector3(x * TextureSize, (y + 1) * TextureSize, 0);

                    ArraySegment <Vector2> UVQuad = new ArraySegment <Vector2>(UVs, (x + y * Tile_Width) * 4, 4);
                    UVQuad[0] = new Vector2(TexU * TextureSize, TexV * TextureSize);
                    UVQuad[1] = new Vector2((TexU + 1) * TextureSize, TexV * TextureSize);
                    UVQuad[2] = new Vector2((TexU + 1) * TextureSize, (TexV + 1) * TextureSize);
                    UVQuad[3] = new Vector2(TexU * TextureSize, (TexV + 1) * TextureSize);
                }
            }

            VertexMesh.SetVertexQuadMesh(Verticies, UVs);
            VertexMesh.Texture = TexturePath;
        }
        public override void ChargeBuffer(ObjMeshContainer objMeshContainer, Mesh dxMesh, int index)
        {
            var objMesh = objMeshContainer.ListObjMesh[index];

            //Cargar VertexBuffer
            using (var vb = dxMesh.VertexBuffer)
            {
                var data = vb.Lock(0, 0, LockFlags.None);
                var v    = new VertexMesh();

                objMesh.FaceTriangles.ForEach(face =>
                {
                    v.Position = objMeshContainer.VertexListV[Convert.ToInt32(face.V1) - 1];
                    v.Normal   = objMeshContainer.VertexListVn[Convert.ToInt32(face.Vn1) - 1];
                    v.Tu0      = objMeshContainer.VertexListVt[Convert.ToInt32(face.Vt1) - 1].X;
                    v.Tv0      = objMeshContainer.VertexListVt[Convert.ToInt32(face.Vt1) - 1].Y;
                    v.Color    = -1; //TODO que corresponde poner aca con respecto obj Mesh
                    data.Write(v);
                    v.Position = objMeshContainer.VertexListV[Convert.ToInt32(face.V2) - 1];
                    v.Normal   = objMeshContainer.VertexListVn[Convert.ToInt32(face.Vn2) - 1];
                    v.Tu0      = objMeshContainer.VertexListVt[Convert.ToInt32(face.Vt2) - 1].X;
                    v.Tv0      = objMeshContainer.VertexListVt[Convert.ToInt32(face.Vt2) - 1].Y;
                    v.Color    = -1; //TODO que corresponde poner aca con respecto obj Mesh
                    data.Write(v);
                    v.Position = objMeshContainer.VertexListV[Convert.ToInt32(face.V3) - 1];
                    v.Normal   = objMeshContainer.VertexListVn[Convert.ToInt32(face.Vn3) - 1];
                    v.Tu0      = objMeshContainer.VertexListVt[Convert.ToInt32(face.Vt3) - 1].X;
                    v.Tv0      = objMeshContainer.VertexListVt[Convert.ToInt32(face.Vt3) - 1].Y;
                    v.Color    = -1; //TODO que corresponde poner aca con respecto obj Mesh
                    data.Write(v);
                });
                vb.Unlock();
            }
            ChargeIndexBuffer(objMesh, dxMesh);
        }
Exemple #5
0
 public void render(VertexMesh vertexMesh)
 {
     renderEffect.Parameters["World"].SetValue(vertexMesh.world);
     graphics.DrawUserIndexedPrimitives<VertexPositionColorNormal>(PrimitiveType.TriangleList, vertexMesh.verts, 0, vertexMesh.verts.Count(), vertexMesh.indices,
         0, 8, VertexPositionColorNormal.VertexDeclaration);
 }