1 |
# Texture coordinates |
# Texture coordinates |
2 |
|
|
3 |
class TexCoords: |
class TexCoords: |
4 |
def _create2DXYVectors(rnd): |
def _create2DXYVectors(self, rnd): |
5 |
"""Create the carefully correlated matrix which gives (x,y) |
"""Create the carefully correlated matrix which gives (x,y) |
6 |
from the texture coordinates (s,t). |
from the texture coordinates (s,t). |
7 |
|
|
44 |
|
|
45 |
return mat |
return mat |
46 |
|
|
47 |
def _invert2Dsimple(mat): |
def _invert2Dsimple(self, mat): |
48 |
"""Invert 2 4D vectors given by _create2DXYVectors to get the vectors |
"""Invert 2 4D vectors given by _create2DXYVectors to get the vectors |
49 |
to dot (x,y,0,1) with to get (s,t) |
to dot (x,y,0,1) with to get (s,t) |
50 |
""" |
""" |
61 |
|
|
62 |
return r |
return r |
63 |
|
|
64 |
def _create3DPlane(rnd): |
def _create3DPlane(self, rnd): |
65 |
"""Get a suitable vector for a plane inside a 3D texture. |
"""Get a suitable vector for a plane inside a 3D texture. |
66 |
|
|
67 |
Returns a 4-component vector; the equation is |
Returns a 4-component vector; the equation is |
82 |
|
|
83 |
return (i, j, k, shift) |
return (i, j, k, shift) |
84 |
|
|
85 |
def _3DPlaneOrthoVecs(v): |
def _3DPlaneOrthoVecs(self, v): |
86 |
"""From a 4-vector (a,b,c,d) describing a plane, create two orthonormal |
"""From a 4-vector (a,b,c,d) describing a plane, create two orthonormal |
87 |
3-vectors plus one 3-offset vector which mean |
3-vectors plus one 3-offset vector which mean |
88 |
(s3,t3,r3) = v_1*s2 + v_2*t2 + v_3 where |
(s3,t3,r3) = v_1*s2 + v_2*t2 + v_3 where |
123 |
return (vec1, vec2, vec3) |
return (vec1, vec2, vec3) |
124 |
|
|
125 |
|
|
126 |
def get2DTexGenData(rnd): |
def get2DTexGenData(self, rnd): |
127 |
"""Get the data to pass to texgen for a single, random |
"""Get the data to pass to texgen for a single, random |
128 |
2D texture coordinate system. |
2D texture coordinate system. |
129 |
""" |
""" |
130 |
vectors = _invert2Dsimple(_create2DXYVectors(rnd)) |
vectors = self._invert2Dsimple(self._create2DXYVectors(rnd)) |
131 |
return [ |
return [ |
132 |
vectors[0][0], |
vectors[0][0], |
133 |
vectors[0][1], |
vectors[0][1], |
140 |
0, 0, 0, 0 |
0, 0, 0, 0 |
141 |
] |
] |
142 |
|
|
143 |
def get3DTexGenData(rnd): |
def get3DTexGenData(self, rnd): |
144 |
"""Get the data to pass to texgen for a single, random |
"""Get the data to pass to texgen for a single, random |
145 |
2D slice of a 3D texture coordinate system. |
2D slice of a 3D texture coordinate system. |
146 |
""" |
""" |
147 |
# Get the transformation from (x,y,z) to |
# Get the transformation from (x,y,z) to |
148 |
# the virtual 2D texture coordinates (s2, t2) |
# the virtual 2D texture coordinates (s2, t2) |
149 |
vectors = _invert2Dsimple(_create2DXYVectors(rnd)) |
vectors = self._invert2Dsimple(self._create2DXYVectors(rnd)) |
150 |
|
|
151 |
# Then, create the transformation from (s2, t3) |
# Then, create the transformation from (s2, t3) |
152 |
# to (s3, t3, r3) |
# to (s3, t3, r3) |
153 |
planevec = _create3DPlane(rnd) |
planevec = self._create3DPlane(rnd) |
154 |
|
|
155 |
# And finally, concatenate the two by matrix |
# And finally, concatenate the two by matrix |
156 |
# multiplication |
# multiplication |
180 |
vectors[2][3], |
vectors[2][3], |
181 |
] |
] |
182 |
|
|
183 |
def getCorrelatedTexGenData(tg, rnd): |
def getCorrelatedTexGenData(self, tg, rnd): |
184 |
sca = 0.07 |
sca = 0.07 |
185 |
return [ |
return [ |
186 |
tg[0], |
tg[0], |