Exemplo n.º 1
0
func (model *Model) Unpack(res *resource.Container) error {
	res.Parse(&model.Header)

	geomCollection := &model.Header.GeometryCollection

	model.Geometry = make([]*Geometry, geomCollection.Count)
	for i := range model.Geometry {
		model.Geometry[i] = new(Geometry)
	}

	err := geomCollection.For(res, func(i int) error {
		geometry := model.Geometry[i]
		if err := geometry.Unpack(res); err != nil {
			return err
		}

		if model.Header.ShaderMappings.Valid() {
			if err := res.PeekElem(model.Header.ShaderMappings, i, &geometry.Shader); err != nil {
				return err
			}
		} else {
			geometry.Shader = ShaderNone
		}
		return nil
	})
	if err != nil {
		return err
	}

	return nil
}