func (this *Mesh) VertexData() *Opengl.OpenGLVertexInfo { vertexData := Opengl.OpenGLVertexInfo{} for _, face := range this.Faces { for idx, vIdx := range face.V { c := this.Materials[face.Material].Diffuse v := this.Vs[vIdx] vdID := vertexData.NewVertex(v.X, v.Y, v.Z) vertexData.SetColor(vdID, c.R, c.G, c.B, 1) tex := this.Materials[face.Material].DiffuseTex if len(face.UV) == 0 || tex == "" { vertexData.SetMode(vdID, Opengl.NO_TEXTURE) } else { imgSec := Image.GetImageSection(GT.AssetsImages + tex) if imgSec == nil { Logging.Info("Cannot open: ", GT.AssetsImages+tex, " For Mat: ", face.Material) } // uvs u := this.VTs[face.UV[idx]].U v := this.VTs[face.UV[idx]].V //normals // x starts from left to right locX := int(float32(imgSec.Bounds().Dx()) * u) // y starts bottom to top so we need to convert. locY := int(float32(imgSec.Bounds().Max.Y) - float32(imgSec.Bounds().Dy())*v) locX += imgSec.Section.Min.X locY += imgSec.Section.Min.Y newU, newV := Image.GetUVFromPosition(image.Point{locX, locY}) vertexData.SetUV(vdID, newU, newV) vertexData.SetMode(vdID, Opengl.TEXTURED) // set normals nX := this.VNs[face.VN[idx]].X nY := this.VNs[face.VN[idx]].Y nZ := this.VNs[face.VN[idx]].Z vertexData.SetMNormal(vdID, nX, nY, nZ) vertexData.SetWNormal(vdID, nX, nY, nZ) } } } return &vertexData }
func (this *Image) VertexData() *Opengl.OpenGLVertexInfo { v := Opengl.OpenGLVertexInfo{} w := float32(this.Bounds().Dx()) h := float32(this.Bounds().Dy()) // first tri idx := v.NewVertex(-0.5*w, -0.5*h, 1.0) v.SetUV(idx, this.uvs[0], this.uvs[1]) v.SetAggregateId(idx, this.aggrId) idx = v.NewVertex(0.5*w, -0.5*h, 1.0) v.SetUV(idx, this.uvs[2], this.uvs[3]) v.SetAggregateId(idx, this.aggrId) idx = v.NewVertex(-0.5*w, 0.5*h, 1.0) v.SetUV(idx, this.uvs[6], this.uvs[7]) v.SetAggregateId(idx, this.aggrId) // second tri idx = v.NewVertex(-0.5*w, 0.5*h, 1.0) v.SetUV(idx, this.uvs[6], this.uvs[7]) v.SetAggregateId(idx, this.aggrId) idx = v.NewVertex(0.5*w, -0.5*h, 1.0) v.SetUV(idx, this.uvs[2], this.uvs[3]) v.SetAggregateId(idx, this.aggrId) idx = v.NewVertex(0.5*w, 0.5*h, 1.0) v.SetUV(idx, this.uvs[4], this.uvs[5]) v.SetAggregateId(idx, this.aggrId) return &v }