Example #1
0
func (vol *Volume) Unpack(res *resource.Container) error {
	res.Parse(&vol.VolumeHeader)

	vol.Mesh = export.NewMesh()

	res.Detour(vol.VerticesAddr, func() error {
		return vol.unpackVertices(res)
	})

	res.Detour(vol.IndicesAddr, func() error {
		return vol.unpackFaces(res)
	})

	return nil
}
Example #2
0
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
}