2018-09-05 13:53:09 +00:00
|
|
|
package main
|
|
|
|
|
2018-09-20 12:41:24 +00:00
|
|
|
import "github.com/divan/three"
|
2018-09-05 13:53:09 +00:00
|
|
|
|
2018-09-05 14:09:56 +00:00
|
|
|
// NewEthereumGeometry creates a geometry for representing Ethereum node (non-regular 3D octahedron).
|
|
|
|
// It scales object according to the given scale.
|
|
|
|
func NewEthereumGeometry(scale float64) three.Geometry {
|
2018-09-05 13:53:09 +00:00
|
|
|
var geom = three.NewBasicGeometry(three.BasicGeometryParams{})
|
|
|
|
vertices := []struct {
|
|
|
|
x, y, z float64
|
|
|
|
}{
|
2018-09-05 14:09:56 +00:00
|
|
|
{scale * 1.0, 0.0, 0.0},
|
|
|
|
{scale * -1.0, 0.0, 0.0},
|
|
|
|
{0.0, scale * 1.5, 0.0},
|
|
|
|
{0.0, scale * -1.5, 0.0},
|
|
|
|
{0.0, 0.0, scale * 1.0},
|
|
|
|
{0.0, 0.0, scale * -1.0},
|
2018-09-05 13:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range vertices {
|
|
|
|
geom.AddVertice(v.x, v.y, v.z)
|
|
|
|
}
|
|
|
|
|
|
|
|
faces := []struct {
|
|
|
|
a, b, c int
|
|
|
|
}{
|
|
|
|
{0, 2, 4},
|
|
|
|
{0, 4, 3},
|
|
|
|
{0, 3, 5},
|
|
|
|
{0, 5, 2},
|
|
|
|
{1, 2, 5},
|
|
|
|
{1, 5, 3},
|
|
|
|
{1, 3, 4},
|
|
|
|
{1, 4, 2},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range faces {
|
|
|
|
geom.AddFace(f.a, f.b, f.c)
|
|
|
|
}
|
|
|
|
|
|
|
|
geom.ComputeBoundingSphere()
|
|
|
|
geom.ComputeFaceNormals()
|
|
|
|
|
|
|
|
return geom
|
|
|
|
}
|