예제 #1
0
파일: counties.go 프로젝트: kirillrdy/pt
func LoadTriangles(path string) []*pt.Triangle {
	materials := make(map[string]pt.Material)
	file, err := os.Open(path)
	if err != nil {
		panic(err)
	}
	defer file.Close()
	rows, err := csv.NewReader(file).ReadAll()
	if err != nil {
		panic(err)
	}
	var result []*pt.Triangle
	for _, row := range rows {
		name := row[0]
		if _, ok := materials[name]; !ok {
			materials[name] = NewMaterial()
		}
		x1, _ := strconv.ParseFloat(row[1], 64)
		y1, _ := strconv.ParseFloat(row[2], 64)
		z1, _ := strconv.ParseFloat(row[3], 64)
		x2, _ := strconv.ParseFloat(row[4], 64)
		y2, _ := strconv.ParseFloat(row[5], 64)
		z2, _ := strconv.ParseFloat(row[6], 64)
		x3, _ := strconv.ParseFloat(row[7], 64)
		y3, _ := strconv.ParseFloat(row[8], 64)
		z3, _ := strconv.ParseFloat(row[9], 64)
		v1 := pt.Vector{x1, y1, z1}
		v2 := pt.Vector{x2, y2, z2}
		v3 := pt.Vector{x3, y3, z3}
		v := pt.Vector{}
		t := pt.NewTriangle(v1, v2, v3, v, v, v, materials[name])
		result = append(result, t)
	}
	return result
}
예제 #2
0
파일: craft.go 프로젝트: noscripter/pt
func Cube(p pt.Vector, material pt.Material, tiles []int) []*pt.Triangle {
	var result []*pt.Triangle
	for i, t := range Triangles {
		tile := tiles[i/2]
		m := pt.Vector{float64(tile%N) / N, float64(tile/N) / N, 0}
		v1, v2, v3 := t[0][0], t[1][0], t[2][0]
		v1, v2, v3 = v1.Add(p), v2.Add(p), v3.Add(p)
		t1, t2, t3 := t[0][1], t[1][1], t[2][1]
		t1, t2, t3 = t1.Add(m), t2.Add(m), t3.Add(m)
		result = append(result, pt.NewTriangle(v1, v2, v3, t1, t2, t3, material))
	}
	return result
}