public Model(int triangles, VertexArray mesh) : base() { this.mesh = mesh; this.triangles = triangles; this.shader = ShaderLibrary.Get("basic"); }
public Axis(Shader shader) : base() { this.shader = shader; this.geometry = new VertexArray(PrimitiveType.Lines); geometry.CreateBuffer("vertex").BufferData<Byte3>(ref vertexData); geometry.CreateBuffer("colors").BufferData<byte>(ref colorData); geometry.AddPointer("vertex", new VertexAttribute(shader, "vPosition", VertexAttribPointerType.UnsignedByte, 3, 0, false)); geometry.AddPointer("colors", new VertexAttribute(shader, "vColor", VertexAttribPointerType.UnsignedByte, 4, 0, true)); }
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; }
public Voxel(Shader shader) : base() { this.shader = shader; geometry = new VertexArray(PrimitiveType.Triangles); vertex = geometry.CreateBuffer("vertex", BufferTarget.ArrayBuffer); colors = geometry.CreateBuffer("colors", BufferTarget.ArrayBuffer); normal = geometry.CreateBuffer("normal", BufferTarget.ArrayBuffer); Byte3[] colorData = ColorData(new Byte3(255, 0, 0), new Byte3(0, 255, 255), new Byte3(0, 255, 0), new Byte3(255, 0, 255), new Byte3(0, 0, 255), new Byte3(255, 255, 0)); vertex.BufferData<Byte3>(ref vertexData); colors.BufferData<Byte3>(ref colorData); normal.BufferData<SByte3>(ref normalData); geometry.AddPointer("vertex", new VertexAttribute(this.shader, "vPosition", VertexAttribPointerType.UnsignedByte, 3, 0, false)); geometry.AddPointer("colors", new VertexAttribute(this.shader, "vColor", VertexAttribPointerType.UnsignedByte, 3, 0, true)); geometry.AddPointer("normal", new VertexAttribute(this.shader, "vNormal", VertexAttribPointerType.Byte, 3, 0, true)); }