package d2isometricimg
import (
"hash/fnv"
"github.com/pancsta/d2/d2renderers/d2isometric"
)
func nativeRouteTint(edge d2isometric .Edge ) string {
if edge .StrokeExplicit {
return edge .Stroke
}
palette := [...]string {"#3d6d8f" , "#36776b" , "#786391" , "#957245" , "#586d86" , "#8c606b" }
h := fnv .New32a ()
_, _ = h .Write ([]byte (edge .ID ))
return palette [int (h .Sum32 ())%len (palette )]
}
func nativeRouteRadius(edge d2isometric .Edge ) float64 {
return max (.012 , min (.075 , float64 (edge .StrokeWidth )*.012 ))
}
func (b *meshBuilder ) routeInk (points []Vec , radius float64 , mat *Material ) {
if len (points ) < 2 || radius <= 0 {
return
}
left , right := make ([]Vertex , len (points )), make ([]Vertex , len (points ))
for i , p := range points {
a , c := points [max (0 , i -1 )], points [min (len (points )-1 , i +1 )]
tangent := nunit (nsub (c , a ))
side := nunit (ncross (tangent , nv (0 , 1 , 0 )))
up := nunit (ncross (side , tangent ))
left [i ] = Vertex {Position : nadd (p , nmul (side , radius )), Normal : up }
right [i ] = Vertex {Position : nsub (p , nmul (side , radius )), Normal : up }
}
for i := 1 ; i < len (points ); i ++ {
b .triangle (left [i -1 ], right [i ], right [i -1 ], mat , false )
b .triangle (left [i -1 ], left [i ], right [i ], mat , false )
}
}
func (b *meshBuilder ) routeCasing (points []Vec , radius float64 , opacity float64 ) {
if len (points ) < 2 {
return
}
mat := nativeMaterial ("#f5f7fb" , 1 , 0 , opacity )
mat .Unlit = true
left , right := make ([]Vertex , len (points )), make ([]Vertex , len (points ))
for i , p := range points {
a , c := points [max (0 , i -1 )], points [min (len (points )-1 , i +1 )]
tangent := nunit (nsub (c , a ))
side := nunit (ncross (tangent , nv (0 , 1 , 0 )))
up := nunit (ncross (side , tangent ))
offset := radius * .8
if b .routeCasingFloor > 0 && up .Y > 1e-9 {
offset = min (offset , max (0 , (p .Y -b .routeCasingFloor )/up .Y ))
}
center := nsub (p , nmul (up , offset ))
left [i ] = Vertex {Position : nadd (center , nmul (side , radius *1.3 )), Normal : up }
right [i ] = Vertex {Position : nsub (center , nmul (side , radius *1.3 )), Normal : up }
}
for i := 1 ; i < len (points ); i ++ {
b .triangle (left [i -1 ], right [i ], right [i -1 ], mat , false )
b .triangle (left [i -1 ], left [i ], right [i ], mat , false )
}
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .