当前位置: 首页>>代码示例>>Golang>>正文


Golang MultiPak.List方法代码示例

本文整理汇总了Golang中github.com/ThomasHabets/qpov/pak.MultiPak.List方法的典型用法代码示例。如果您正苦于以下问题:Golang MultiPak.List方法的具体用法?Golang MultiPak.List怎么用?Golang MultiPak.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ThomasHabets/qpov/pak.MultiPak的用法示例。


在下文中一共展示了MultiPak.List方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: convert

func convert(p pak.MultiPak, args ...string) {
	fs := flag.NewFlagSet("convert", flag.ExitOnError)
	fs.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s -pak <pak0,pak1,...> convert [options]\n", os.Args[0])
		fs.PrintDefaults()
	}
	outDir := fs.String("out", ".", "Output directory.")
	skins := fs.Bool("skins", true, "Use skins.")
	fs.Parse(args)

	errors := []string{}
	os.Mkdir(*outDir, 0755)
	for _, mf := range p.List() {
		if path.Ext(mf) != ".mdl" {
			continue
		}
		func() {
			o, err := p.Get(mf)
			if err != nil {
				log.Fatalf("Getting %q: %v", mf, err)
			}

			m, err := mdl.Load(o)
			if err != nil {
				log.Printf("Loading %q: %v", mf, err)
				errors = append(errors, mf)
				return
			}
			var cparts []string
			for _, part := range strings.Split(mf, "/") {
				cparts = append(cparts, part)
				if err := os.Mkdir(path.Join(*outDir, strings.Join(cparts, "/")), 0755); err != nil {
					//log.Printf("Creating model subdir: %v, continuing...", err)
				}
			}
			fn := fmt.Sprintf(path.Join(mf, "model.inc"))
			of, err := os.Create(path.Join(*outDir, fn))
			if err != nil {
				log.Fatalf("Model create of %q fail: %v", fn, err)
			}
			defer of.Close()
			for n := range m.Frames {
				if *skins {
					fmt.Fprintf(of, "#macro %s(pos, rot, skin)\n%s\n#end\n", frameName(mf, n), m.POVFrameID(n, "skin"))
				} else {
					fmt.Fprintf(of, "#macro %s(pos, rot)\n%s\n#end\n", frameName(mf, n), m.POVFrameID(n, ""))
				}
			}

			for n, skin := range m.Skins {
				of, err := os.Create(path.Join(*outDir, mf, fmt.Sprintf("skin_%d.png", n)))
				if err != nil {
					log.Fatalf("Skin create of %q fail: %v", fn, err)
				}
				defer of.Close()
				if err := (&png.Encoder{CompressionLevel: pngCompressionLevel}).Encode(of, skin); err != nil {
					log.Fatalf("Encoding skin to png: %v", err)
				}
			}
		}()
	}
	if len(errors) > 0 {
		fmt.Printf("Failed to convert %d models:\n  %s\n", len(errors), strings.Join(errors, "\n  "))
	}
}
开发者ID:DaveRichmond,项目名称:qpov,代码行数:65,代码来源:mdl_main.go

示例2: convert

func convert(p pak.MultiPak, args ...string) {
	fs := flag.NewFlagSet("convert", flag.ExitOnError)
	fs.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s -pak pak0,pak1,... convert [options]\n", os.Args[0])
		fs.PrintDefaults()
	}
	outDir := fs.String("out", ".", "Output directory.")
	retexturePack := fs.String("retexture", "", "Path to retexture pack.")
	flatColor := fs.String("flat_color", "<0.25,0.25,0.25>", "")
	textures := fs.Bool("textures", true, "Use textures.")
	lights := fs.Bool("lights", false, "Export lights.")
	maps := fs.String("maps", ".*", "Maps regex.")
	fs.Parse(args)

	re, err := regexp.Compile(*maps)
	if err != nil {
		log.Fatalf("Maps regex %q invalid: %v", *maps, err)
	}

	//errors := []string{}
	os.Mkdir(*outDir, 0755)
	for _, mf := range p.List() {
		if path.Ext(mf) != ".bsp" {
			continue
		}
		if !re.MatchString(mf) {
			continue
		}
		func() {
			o, err := p.Get(mf)
			if err != nil {
				log.Fatalf("Getting %q: %v", mf, err)
			}

			b, err := bsp.Load(o)
			if err != nil {
				log.Fatalf("Loading %q: %v", mf, err)
			}

			mkdirP(*outDir, mf)
			fn := fmt.Sprintf(path.Join(mf, "level.inc"))
			of, err := os.Create(path.Join(*outDir, fn))
			if err != nil {
				log.Fatalf("Model create of %q fail: %v", fn, err)
			}
			defer of.Close()
			m, err := b.POVTriangleMesh(bsp.ModelMacroPrefix(mf), *textures, *flatColor)
			if err != nil {
				log.Fatalf("Making mesh of %q: %v", mf, err)
			}
			fmt.Fprintln(of, m)
			if *lights {
				fmt.Fprintln(of, b.POVLights())
			}

			if *textures {
				for n, texture := range b.Raw.MipTexData {
					fn := path.Join(*outDir, mf, fmt.Sprintf("texture_%d.png", n))
					retexFn, retex := retexture(*retexturePack, mf, b.Raw.MipTex[n], texture)
					if retex {
						if err := os.Symlink(retexFn, fn); err != nil {
							log.Fatalf("Failed to symlink %q to %q for texture pack: %v", fn, retexFn, err)
						}
						continue
					}
					func() {
						of, err := os.Create(fn)
						if err != nil {
							log.Fatalf("Texture create of %q fail: %v", fn, err)
						}
						defer of.Close()
						if err := (&png.Encoder{CompressionLevel: pngCompressionLevel}).Encode(of, texture); err != nil {
							log.Fatalf("Encoding texture to png: %v", err)
						}
					}()
				}
			}

		}()
	}
}
开发者ID:DaveRichmond,项目名称:qpov,代码行数:81,代码来源:bsp_main.go


注:本文中的github.com/ThomasHabets/qpov/pak.MultiPak.List方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。