func (nodes *Nodes) Unpack(res *resource.Container) error { res.Parse(&nodes.NodesHeader) var err error nodes.Volumes = make([]*Volume, nodes.Capacity) volCollection := resource.PointerCollection{ Addr: nodes.BoundsTable, Count: nodes.Count, Capacity: nodes.Capacity, } volInfoCollection := resource.Collection{ Addr: nodes.VolumeInfo, Count: nodes.Count, Capacity: nodes.Capacity, } err = volInfoCollection.For(res, func(i int) error { nodes.Volumes[i] = new(Volume) if err := nodes.Volumes[i].VolumeInfo.Unpack(res); err != nil { return err } return nil }) if err != nil { return err } err = volCollection.For(res, func(i int) error { return nodes.Volumes[i].Unpack(res) }) if err != nil { return err } nodes.Model = export.NewModel() for _, vol := range nodes.Volumes { nodes.Model.AddMesh(vol.Mesh) } return nil }
func (drawable *Drawable) Unpack(res *resource.Container) error { res.Parse(&drawable.Header) drawable.Model = export.NewModel() /* unpack */ if drawable.Header.ShaderTable.Valid() { if err := res.Detour(drawable.Header.ShaderTable, func() error { return drawable.Shaders.Unpack(res) }); err != nil { return err } } if err := res.Detour(drawable.Header.ModelCollection, func() error { return drawable.Models.Unpack(res) }); err != nil { return err } if drawable.Header.Title.Valid() { if err := res.Detour(drawable.Header.Title, func() error { res.Parse(&drawable.Title) drawable.Title = drawable.Title[:strings.LastIndex(drawable.Title, ".")] return nil }); err != nil { return err } } else { drawable.Title = fmt.Sprintf("unnamed_%v", NextUnnamedIndex) NextUnnamedIndex++ } /* Load everything into our exportable */ drawable.Model.Name = drawable.Title for _, shader := range drawable.Shaders.Shaders { material := export.NewMaterial() if shader.DiffusePath != "" { material.DiffBitmap = fmt.Sprintf("%v.dds", shader.DiffusePath) } drawable.Model.AddMaterial(material) } for _, model := range drawable.Models.Models { for _, geom := range model.Geometry { mesh := export.NewMesh() mesh.Material = int(geom.Shader) for _, vert := range geom.Vertices.Vertex { /* Even if a feature isn't supported, the nil value should be fine */ newVert := export.Vertex{ Pos: mathgl.Vec4f{ vert.WorldCoord[0], vert.WorldCoord[1], vert.WorldCoord[2], 1.0, }, UV: mathgl.Vec2f{ vert.UV0.U.Value(), (-vert.UV0.V.Value()) + 1, }, Colour: vert.Colour, } mesh.AddVert(newVert) } mesh.Format = geom.Vertices.Format for _, face := range geom.Indices.Index { mesh.AddFace(*face) } drawable.Model.AddMesh(mesh) } } return nil }