func (buf *IndexBuffer) Unpack(res *resource.Container) error { buf.Stride = 3 * 2 // 3*uint16 /* is this stored anywhere? */ res.Parse(&buf.IndexHeader) buf.Index = make([]*types.Tri, buf.Count/3) for i := range buf.Index { buf.Index[i] = new(types.Tri) } if err := res.Detour(buf.Buffer, func() error { buffer := make([]byte, buf.Stride) reader := bytes.NewReader(buffer) for _, idx := range buf.Index { /* Read the index into our local buffer */ if size, err := res.Read(buffer); size != buf.Stride || err != nil { return err } /* Parse out the info we can */ if err := binary.Read(reader, binary.BigEndian, idx); err != nil { return err } reader.Seek(0, 0) } return nil }); err != nil { return err } return nil }
func (vert *Vertex) Unpack(res *resource.Container, buf *VertexBuffer) error { buffer := make([]byte, buf.Stride) reader := bytes.NewReader(buffer) /* Read the vertex into our local buffer */ if size, err := res.Read(buffer); uint16(size) != buf.Stride || err != nil { return err } offset := 0 /* Parse out the info we can */ if buf.Format.Has(export.VertXYZ) { if err := binary.Read(reader, binary.BigEndian, &vert.WorldCoord); err != nil { return err } offset += (4 * 3) } if buf.Format.Has(export.VertUnkA) { junk := make([]byte, 4) reader.Read(junk) offset += 4 } if buf.Format.Has(export.VertUnkB) { junk := make([]byte, 4) reader.Read(junk) offset += 4 } if buf.Format.Has(export.VertUnkC) { junk := make([]byte, 4) reader.Read(junk) offset += 4 } if buf.Format.Has(export.VertColour) { if err := binary.Read(reader, binary.BigEndian, &vert.Colour); err != nil { return err } offset += 4 } if buf.Format.Has(export.VertUnkD) { junk := make([]byte, 4) reader.Read(junk) offset += 4 } if buf.Format.Has(export.VertUV0) { if err := binary.Read(reader, binary.BigEndian, &vert.UV0); err != nil { return err } offset += 4 } if buf.Format.Has(export.VertUV1) { if err := binary.Read(reader, binary.BigEndian, &vert.UV1); err != nil { return err } offset += 4 } if buf.Format.Has(export.VertUnkX) { junk := make([]byte, 4) reader.Read(junk) offset += 4 } return nil }