Example #1
0
func (group *Group) Unpack(res *resource.Container) error {
	res.Parse(&group.GroupHeader)

	/* Read any texture dictionary */
	if group.TexturePtr.Valid() {
		if err := res.Detour(group.TexturePtr, func() error {
			group.Texture = new(texture.Texture)
			return group.Texture.Unpack(res)
		}); err != nil {
			return err
		}
	}

	/* Read our shader headers */
	group.Shaders = make([]*Shader, group.Count)
	for i := range group.Shaders {
		group.Shaders[i] = new(Shader)
	}

	/* Read the shaders */
	for i, shader := range group.Shaders {
		if err := group.Detour(res, i, func() error {
			if err := shader.Unpack(res); err != nil {
				return err
			}
			return nil
		}); err != nil {
			log.Printf("Error reading shader %v\n", i)
			return err
		}
	}

	return nil
}
Example #2
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
}
Example #3
0
func (shader *Shader) Unpack(res *resource.Container) error {
	res.Parse(&shader.Header)

	shader.Parameters = make([]*Parameter, shader.ParameterCount)
	for i := range shader.Parameters {
		shader.Parameters[i] = new(Parameter)
	}

	if err := res.Detour(shader.ParameterList, func() error {
		for _, param := range shader.Parameters {
			if err := param.Unpack(res); err != nil {
				return err
			}

			if param.parameter != nil {
				var err error
				switch param.Type {
				case ParamDiffuseBitmap:
					shader.DiffusePath, err = param.parameter.(*BitmapParameter).Get(res)
				case ParamNormalBitmap:
					shader.NormalPath, err = param.parameter.(*BitmapParameter).Get(res)
				}
				if err != nil {
					return err
				}
			}

		}
		return nil
	}); err != nil {
		return err
	}

	return nil
}
Example #4
0
func (texture *Texture) Unpack(res *resource.Container) error {
	res.Parse(&texture.Header)

	texture.Bitmaps = make(Bitmaps, texture.Header.Bitmaps.Capacity)
	if err := texture.Bitmaps.Unpack(res, &texture.Header.Bitmaps); err != nil {
		return err
	}

	return nil
}
Example #5
0
func (dict *Dictionary) Unpack(res *resource.Container) error {
	res.Parse(&dict.Header)

	dict.DrawableCollection.PointerCollection = dict.Header.DrawableCollection
	if err := dict.DrawableCollection.Unpack(res); err != nil {
		return err
	}

	return nil
}
Example #6
0
func (frag *FragType) Unpack(res *resource.Container) error {
	res.Parse(&frag.Header)

	if err := res.Detour(frag.Header.Drawable, func() error {
		frag.Drawable.Unpack(res)
		return nil
	}); err != nil {
		return err
	}
	return nil
}
Example #7
0
func (vol *Volume) unpackVertices(res *resource.Container) error {
	for i := 0; i < int(vol.VertexCount); i++ {
		iVec := new(types.Vec3i)
		res.Parse(iVec)
		x := (float32(iVec[0]) * vol.ScaleFactor[0]) + vol.Offset[0]
		y := (float32(iVec[1]) * vol.ScaleFactor[1]) + vol.Offset[1]
		z := (float32(iVec[2]) * vol.ScaleFactor[2]) + vol.Offset[2]
		v := mathgl.Vec4f{x, y, z, 1.0}
		vol.AddVert4f(v)
	}

	return nil
}
Example #8
0
func (buf *VertexBuffer) Unpack(res *resource.Container) error {
	res.Parse(&buf.VertexHeader)

	if err := res.Detour(buf.Info, func() error {
		res.Parse(&buf.VertexInfo)
		return nil
	}); err != nil {
		return err
	}

	buf.Vertex = make([]*Vertex, buf.Count)
	for i := range buf.Vertex {
		buf.Vertex[i] = new(Vertex)
	}

	if err := res.Detour(buf.Buffer, func() error {
		for _, vert := range buf.Vertex {
			if err := vert.Unpack(res, buf); err != nil {
				return err
			}
		}
		return nil
	}); err != nil {
		return err
	}
	return nil
}
Example #9
0
func (bmp *BitmapParameter) Get(res *resource.Container) (string, error) {
	if !bmp.Path.Valid() {
		return "", nil
	}

	var path string
	if err := res.Detour(bmp.Path, func() error {
		res.Parse(&path)
		return nil
	}); err != nil {
		return "", err
	}

	return path, nil
}
Example #10
0
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
}
Example #11
0
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
}
Example #12
0
func (param *Parameter) Unpack(res *resource.Container) error {
	res.Parse(&param.ParameterHeader)

	if !param.Offset.Valid() {
		return nil
	}

	switch param.Type {
	case ParamDiffuseBitmap, ParamNormalBitmap:
		bitmap := new(BitmapParameter)
		if err := res.Detour(param.Offset, func() error {
			res.Parse(bitmap)
			param.parameter = bitmap
			return nil
		}); err != nil {
			return err
		}

	default:
		/* unsupported parameter. don't bother giving an error for now */
		param.parameter = nil
	}

	return nil
}
Example #13
0
func (col *ModelCollection) Unpack(res *resource.Container) error {
	res.Parse(&col.PointerCollection)

	col.Models = make([]*Model, col.Count)
	for i := range col.Models {
		col.Models[i] = new(Model)
	}

	/* Read our model headers */
	for i, model := range col.Models {
		if err := col.Detour(res, i, func() error {
			if err := model.Unpack(res); err != nil {
				log.Printf("Error reading model")
				return err
			}
			return nil
		}); err != nil {
			return err
		}
	}

	return nil
}
Example #14
0
func (b *Bitmap) Unpack(res *resource.Container) error {
	res.Parse(&b.Header)

	if b.Header.Title.Valid() {
		res.Detour(b.Header.Title, func() error {
			res.Parse(&b.Title)
			return nil
		})
	}
	return nil
}
Example #15
0
func (vol *Volume) unpackFaces(res *resource.Container) error {
	fixIndex := func(c uint16) uint16 {
		c &= 0x7FFF
		return c
	}

	for i := 0; i < int(vol.IndexCount); i++ {
		var polygonType, junk uint16
		res.Parse(&junk)
		res.Parse(&polygonType)
		idxValues := make([]uint16, 6)
		res.Parse(idxValues)

		debug := func(junk, polyType uint16, idxValues []uint16) {
			fmt.Printf("%.4x ", junk)
			fmt.Printf("%.4x ", polyType)
			for _, i := range idxValues {
				fmt.Printf("%.4x ", i)
			}
			fmt.Printf("\n")
		}

		polygonType &= 0xF
		if polygonType == 0x4 {
			//			debug(junk, polygonType, idxValues)
		} else if polygonType == 0x3 || polygonType == 0xB {
			/* cube, 4 points specified */
			a := fixIndex(idxValues[0])
			b := fixIndex(idxValues[1])
			c := fixIndex(idxValues[2])
			d := fixIndex(idxValues[3])
			buildCube(vol.Mesh, a, b, c, d)
		} else if polygonType == 0x2 {
			/* seems to be two points */
			a := fixIndex(junk)
			b := fixIndex(idxValues[2])
			traceVerts(vol.Mesh, a, b)
		} else if polygonType == 0x1 {
			//			debug(junk, polygonType, idxValues)
		} else if polygonType == 0x0 || polygonType == 0x8 { /* it's probably a triangle */
			a := fixIndex(idxValues[0])
			b := fixIndex(idxValues[1])
			c := fixIndex(idxValues[2])
			vol.AddFace(types.Tri{
				A: a,
				B: b,
				C: c,
			})
		} else {
			debug(junk, polygonType, idxValues)
		}
	}
	return nil
}
Example #16
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 #17
0
func (geom *Geometry) Unpack(res *resource.Container) error {
	res.Parse(&geom.GeometryHeader)

	if err := res.Detour(geom.VertexBuffer, func() error {
		return geom.Vertices.Unpack(res)
	}); err != nil {
		log.Printf("error parsing vertex buffer")
	}

	if err := res.Detour(geom.IndexBuffer, func() error {
		return geom.Indices.Unpack(res)
	}); err != nil {
		log.Printf("error parsing index buffer")
	}
	return nil
}
Example #18
0
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
}
Example #19
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
}
Example #20
0
func (info *VolumeInfo) Unpack(res *resource.Container) error {
	res.Parse(&info.VolumeInfoHeader)

	return nil
}