59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package threedb
|
|
|
|
import "encoding/json"
|
|
|
|
type Model struct {
|
|
DBVersion, Name string
|
|
Materials []Material
|
|
Meshes []Mesh
|
|
Objects map[string][]uint32
|
|
Animations []Animation
|
|
Triangles [][]uint16
|
|
TextureCoordinates [][]Coordinate
|
|
Points [][]Vector
|
|
Brightness [][]byte
|
|
|
|
view ModelView
|
|
}
|
|
|
|
type ModelView interface {
|
|
Prepare(*Model)
|
|
}
|
|
|
|
func (m Model) MarshalJSON() ([]byte, error) {
|
|
if m.view == nil {
|
|
m.view = &DefaultModelView{}
|
|
}
|
|
m.view.Prepare(&m)
|
|
return json.Marshal(m.view)
|
|
}
|
|
|
|
type DefaultModelView struct {
|
|
DBVersion, Name string
|
|
MeshesCount int
|
|
Meshes []int
|
|
FirstMesh Mesh
|
|
Materials []Material
|
|
Animations []Animation
|
|
Triangles int
|
|
TextureCoordinates int
|
|
Points int
|
|
Brightness int
|
|
}
|
|
|
|
func (v *DefaultModelView) Prepare(m *Model) {
|
|
v.DBVersion = m.DBVersion
|
|
v.Name = m.Name
|
|
v.MeshesCount = len(m.Meshes)
|
|
for _, mesh := range m.Meshes {
|
|
v.Meshes = append(v.Meshes, len(mesh.Links))
|
|
}
|
|
v.FirstMesh = m.Meshes[0]
|
|
v.Materials = m.Materials
|
|
v.Animations = m.Animations
|
|
v.Triangles = len(m.Triangles)
|
|
v.TextureCoordinates = len(m.TextureCoordinates)
|
|
v.Points = len(m.Points)
|
|
v.Brightness = len(m.Brightness)
|
|
}
|