Пример #1
0
func surfacePosNormList(surf *md3.Surface, frame int, output chan<- surfaceStringPair) {
	buffer := new(bytes.Buffer)
	vertCount := surf.NumVertices()

	for vertIndex := 0; vertIndex < vertCount; vertIndex++ {
		posNorm := surf.Vertex(frame, vertIndex)
		if *swapYZ {
			var t float32
			t = posNorm.Origin.Y
			posNorm.Origin.Y = posNorm.Origin.Z
			posNorm.Origin.Z = t
			t = posNorm.Normal.Y
			posNorm.Normal.Y = posNorm.Normal.Z
			posNorm.Normal.Z = t
		}
		_, err := fmt.Fprintf(buffer,
			"v %f %f %f\nvn %f %f %f\n",
			posNorm.Origin.X, posNorm.Origin.Y, posNorm.Origin.Z,
			posNorm.Normal.X, posNorm.Normal.Y, posNorm.Normal.Z)
		if err != nil {
			panic(err)
		}
	}

	output <- surfaceStringPair{surf, buffer.String()}
}
Пример #2
0
func surfaceTexCoordList(surf *md3.Surface, output chan<- surfaceStringPair) {
	buffer := new(bytes.Buffer)
	vertCount := surf.NumVertices()

	for vertIndex := 0; vertIndex < vertCount; vertIndex++ {
		texCoord := surf.TexCoord(vertIndex)

		if *flipUVs {
			texCoord.T = 1.0 - texCoord.T
		}

		_, err := fmt.Fprintf(buffer, "vt %f %f\n",
			texCoord.S, texCoord.T)
		if err != nil {
			panic(err)
		}
	}

	output <- surfaceStringPair{surf, buffer.String()}
}
Пример #3
0
func surfaceTriangleList(surf *md3.Surface, baseVertex int, output chan<- surfaceStringPair) {
	var err error
	buffer := new(bytes.Buffer)
	triCount := surf.NumTriangles()
	for triIndex := 0; triIndex < triCount; triIndex++ {
		tri := surf.Triangle(triIndex)
		if *swapYZ {
			_, err = fmt.Fprintf(buffer, "f %[1]d/%[1]d/%[1]d %[2]d/%[2]d/%[2]d %[3]d/%[3]d/%[3]d\n",
				baseVertex+int(tri.A), baseVertex+int(tri.B), baseVertex+int(tri.C))
		} else {
			_, err = fmt.Fprintf(buffer, "f %[3]d/%[3]d/%[3]d %[2]d/%[2]d/%[2]d %[1]d/%[1]d/%[1]d\n",
				baseVertex+int(tri.A), baseVertex+int(tri.B), baseVertex+int(tri.C))
		}
		if err != nil {
			panic(err)
		}
	}

	output <- surfaceStringPair{surf, buffer.String()}
}
Пример #4
0
func writeOBJSurface(w io.Writer, surf *md3.Surface, posNorms, texCoords, triangles map[*md3.Surface]string) error {
	fmt.Fprintf(w, "g %s\n", surf.Name())
	n, err := io.WriteString(w, posNorms[surf])
	if err != nil {
		return err
	} else if n < len(posNorms[surf]) {
		return fmt.Errorf("Error writing positions and normals: only %d of %d bytes written")
	}
	n, err = io.WriteString(w, texCoords[surf])
	if err != nil {
		return err
	} else if n < len(texCoords[surf]) {
		return fmt.Errorf("Error writing texcoords: only %d of %d bytes written")
	}
	n, err = io.WriteString(w, triangles[surf])
	if n < len(triangles[surf]) {
		return fmt.Errorf("Error writing triangles: only %d of %d bytes written")
	}
	return err
}