當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Container.Detour方法代碼示例

本文整理匯總了Golang中github.com/tgascoigne/xdr2obj/resource.Container.Detour方法的典型用法代碼示例。如果您正苦於以下問題:Golang Container.Detour方法的具體用法?Golang Container.Detour怎麽用?Golang Container.Detour使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/tgascoigne/xdr2obj/resource.Container的用法示例。


在下文中一共展示了Container.Detour方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Unpack

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
}
開發者ID:Shader2006,項目名稱:xdr2obj,代碼行數:31,代碼來源:gpu_buffers.go

示例2: Unpack

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
}
開發者ID:Shader2006,項目名稱:xdr2obj,代碼行數:25,代碼來源:parameter.go

示例3: Get

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
}
開發者ID:Shader2006,項目名稱:xdr2obj,代碼行數:15,代碼來源:parameter.go

示例4: Unpack

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
}
開發者ID:Shader2006,項目名稱:xdr2obj,代碼行數:15,代碼來源:volume.go

示例5: Unpack

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
}
開發者ID:Shader2006,項目名稱:xdr2obj,代碼行數:78,代碼來源:drawable.go


注:本文中的github.com/tgascoigne/xdr2obj/resource.Container.Detour方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。