-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtex.py
36 lines (26 loc) · 855 Bytes
/
tex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import math
from point import *
texsizes = {
"NATURE/SWAMP_TREES_CARD01" : (1024,1024),
"NATURE/SWAMP_TREES_CARD02" : (1024,1024),
"NATURE/SWAMP_TREES_CARD02a": (1024,1024),
"TOOLS/TOOLSNODRAW" : ( 64, 64),
"TOOLS/TOOLSSKYBOX" : ( 128, 128),
"CONCRETE/CONCRETE_EXT_03" : ( 512, 512),
}
# figure out the texture axes, shifts, and scales to "fit" on the polygon
# same as the Fit button in Hammer
def texfit( a, b, c, tex=None, texw=512, texh=512 ):
if tex in texsizes: texw,texh = texsizes[tex]
u = a - b
v = b - c
mu = magnitude(u)
mv = magnitude(v)
uscale = mu/(texw)
vscale = mv/(texh)
normalize(u,mu)
normalize(v,mv)
ushift = -math.fmod( dotproduct(u,a)/uscale, texw )
vshift = -math.fmod( dotproduct(v,a)/vscale, texh )
return (u.x,u.y,u.z,ushift,uscale, v.x,v.y,v.z,vshift,vscale)
# vim: sw=8 ts=8 noet