Пример #1
0
        public Model Assemble()
        {
            if (vertexNormals.Count == 0)
                calculateNormals();

            Vector3[] vertexData = verticies.ToArray();
            Vector3[] normals = vertexNormals.ToArray();
            Byte3[] colors = new Byte3[vertexData.Length];
            ushort[] indices = new ushort[faces.Count * 3];

            Byte3 color = new Byte3(45, 35, 200);
            for(int i = 0; i < colors.Length; i++)
                colors[i] = color;

            int j = 0;
            foreach(UInt3 f in faces) {
                indices[j++] = (ushort)(f.Z - 1);
                indices[j++] = (ushort)(f.Y - 1);
                indices[j++] = (ushort)(f.X - 1);
            }

            VertexArray mesh = new VertexArray();
            mesh.CreateBuffer("vertex").BufferData<Vector3>(ref vertexData);
            mesh.CreateBuffer("normal").BufferData<Vector3>(ref normals);
            mesh.CreateBuffer("colors").BufferData<Byte3>(ref colors);
            mesh.CreateBuffer("index", BufferTarget.ElementArrayBuffer).BufferData<ushort>(ref indices);

            Model model = new Model(faces.Count, mesh);

            mesh.AddPointer("vertex",
                new VertexAttribute(model.Shader, "vPosition", VertexAttribPointerType.Float, 3, 0, false));
            mesh.AddPointer("colors",
                new VertexAttribute(model.Shader, "vColor", VertexAttribPointerType.UnsignedByte, 3, 0, true));
            mesh.AddPointer("normal",
                new VertexAttribute(model.Shader, "vNormal", VertexAttribPointerType.Float, 3, 0, false));

            return model;
        }
Пример #2
0
 /* GL_BYTE x3, Normalized */
 protected static Byte3[] ColorData(
     Byte3 xpos, Byte3 xneg, 
     Byte3 ypos, Byte3 yneg, 
     Byte3 zpos, Byte3 zneg
 )
 {
     Byte3[] colors = new Byte3[36];
     for(int i = 0; i < 6; i++)
         colors[i] = xpos;
     for(int i = 6; i < 12; i++)
         colors[i] = xneg;
     for(int i = 12; i < 18; i++)
         colors[i] = ypos;
     for(int i = 18; i < 24; i++)
         colors[i] = yneg;
     for(int i = 24; i < 30; i++)
         colors[i] = zpos;
     for(int i = 30; i < 36; i++)
         colors[i] = zneg;
     return colors;
 }