summaryrefslogtreecommitdiff
path: root/stl.go
diff options
context:
space:
mode:
Diffstat (limited to 'stl.go')
-rw-r--r--stl.go42
1 files changed, 20 insertions, 22 deletions
diff --git a/stl.go b/stl.go
index d024b13..35e69eb 100644
--- a/stl.go
+++ b/stl.go
@@ -53,24 +53,24 @@ func ParseBinaryStlTriangle(data []byte) *Triangle { // FIXME: This function sh
// allocate a new triangle and three corner points on the heap
triangle := new(Triangle)
- triangle.a = new(Point) // corner point a
- triangle.b = new(Point) // corner point b
- triangle.c = new(Point) // corner point c
+ triangle.points[0] = new(Point)
+ triangle.points[1] = new(Point)
+ triangle.points[2] = new(Point)
// parse x, y and z coordinate for corner point a
- triangle.a.x = math.Float32frombits(binary.LittleEndian.Uint32(data[12:16]))
- triangle.a.y = math.Float32frombits(binary.LittleEndian.Uint32(data[16:20]))
- triangle.a.z = math.Float32frombits(binary.LittleEndian.Uint32(data[20:24]))
+ triangle.points[0].scalars[0] = math.Float32frombits(binary.LittleEndian.Uint32(data[12:16]))
+ triangle.points[0].scalars[1] = math.Float32frombits(binary.LittleEndian.Uint32(data[16:20]))
+ triangle.points[0].scalars[2] = math.Float32frombits(binary.LittleEndian.Uint32(data[20:24]))
// parse x, y and z coordinate for corner point b
- triangle.b.x = math.Float32frombits(binary.LittleEndian.Uint32(data[24:28]))
- triangle.b.y = math.Float32frombits(binary.LittleEndian.Uint32(data[28:32]))
- triangle.b.z = math.Float32frombits(binary.LittleEndian.Uint32(data[32:36]))
+ triangle.points[1].scalars[0] = math.Float32frombits(binary.LittleEndian.Uint32(data[24:28]))
+ triangle.points[1].scalars[1] = math.Float32frombits(binary.LittleEndian.Uint32(data[28:32]))
+ triangle.points[1].scalars[2] = math.Float32frombits(binary.LittleEndian.Uint32(data[32:36]))
// parse x, y and z coordinate for corner point c
- triangle.c.x = math.Float32frombits(binary.LittleEndian.Uint32(data[36:40]))
- triangle.c.y = math.Float32frombits(binary.LittleEndian.Uint32(data[40:44]))
- triangle.c.z = math.Float32frombits(binary.LittleEndian.Uint32(data[44:48]))
+ triangle.points[2].scalars[0] = math.Float32frombits(binary.LittleEndian.Uint32(data[36:40]))
+ triangle.points[2].scalars[1] = math.Float32frombits(binary.LittleEndian.Uint32(data[40:44]))
+ triangle.points[2].scalars[2] = math.Float32frombits(binary.LittleEndian.Uint32(data[44:48]))
return triangle
}
@@ -79,19 +79,17 @@ func (stl StlModel) toVertices() []float32 {
retval := make([]float32, stl.numberOfTriangles * 9)
- for index,triangle := range(stl.surface.triangles) {
+ for triangleIndex,triangle := range(stl.surface.triangles) {
- retval[index*9+0] = triangle.a.x
- retval[index*9+1] = triangle.a.y
- retval[index*9+2] = triangle.a.z
+ for pointIndex,point := range(triangle.points) {
- retval[index*9+3] = triangle.b.x
- retval[index*9+4] = triangle.b.y
- retval[index*9+5] = triangle.b.z
+ for scalarIndex,scalar := range(point.scalars) {
- retval[index*9+6] = triangle.c.x
- retval[index*9+7] = triangle.c.y
- retval[index*9+8] = triangle.c.z
+ retval[triangleIndex*9+pointIndex*3+scalarIndex] = scalar
+
+ }
+
+ }
}