Пример #1
0
func performConvertModel(modelPath string, model *md3.Model, signal chan<- bool, writeQueue chan<- func()) {

	waitSignal := make(chan bool)
	triLists := objTriangleLists(model)
	tcLists := objTexCoordLists(model)

	var _ = triLists
	var _ = tcLists

	name := path.Base(modelPath)
	name = name[:len(name)-len(path.Ext(name))]
	dir := path.Clean(*outputPath)
	os.MkdirAll(dir, 0755)

	numFrames := model.NumFrames()

	for frame := 0; frame < numFrames; frame++ {
		go func(frame int) {
			writeQueue <- func() {
				defer func(waitSignal chan<- bool) {
					go func() { waitSignal <- true }()
				}(waitSignal)

				var err error
				var file *os.File
				outName := fmt.Sprintf("%s+%d.obj", name, frame)
				outPath := path.Join(dir, outName)

				file, err = os.Create(outPath)
				if err != nil {
					log.Println("Error creating", outPath, "from", modelPath, "->", err)
					return
				}
				defer file.Close()

				_, err = fmt.Fprintf(file, "o %s\n", model.Name())
				if err != nil {
					log.Println("Error writing header for", outPath, "from", modelPath, "->", err)
				}

				numSurfaces := model.NumSurfaces()
				posNorms := objPosNormLists(model, frame)
				for surfIndex := 0; surfIndex < numSurfaces; surfIndex++ {
					surf := model.Surface(surfIndex)
					err = writeOBJSurface(file, surf, posNorms, tcLists, triLists)
					if err != nil {
						log.Println("Error writing surface for", outPath, "from", modelPath, "->", err)
						return
					}
				}
			}
		}(frame)
	}

	for frame := 0; frame < numFrames; frame++ {
		<-waitSignal
	}

	signal <- true
}
Пример #2
0
func logModelSpec(model *md3.Model) {
	fmt.Printf("MD3(%s):\n", stringOrEmpty(model.Name(), "no name"))
	fmt.Printf("  Frames: %d\n", model.NumFrames())
	fmt.Printf("  Tags(%d):\n", model.NumTags())
	for tag := range model.Tags() {
		fmt.Printf("    %s\n", tag.Name())
	}
	fmt.Printf("  Surfaces(%d):\n", model.NumSurfaces())
	for surf := range model.Surfaces() {
		fmt.Printf("    %s:\n", stringOrEmpty(surf.Name(), "(no name)"))
		if surf.NumFrames() != model.NumFrames() {
			fmt.Printf("      Frames:    %d\n", surf.NumFrames())
		}
		fmt.Printf("      Vertices:  %d\n", surf.NumVertices())
		fmt.Printf("      Triangles: %d\n", surf.NumTriangles())
		fmt.Printf("      Shaders[%d]:\n", surf.NumShaders())
		for shader := range surf.Shaders() {
			fmt.Printf("        Shader[%d]: %s\n", shader.Index, stringOrEmpty(shader.Name, "(no name)"))
		}
	}
}