Skip to content

Commit

Permalink
fixed texture bug holy shit hype
Browse files Browse the repository at this point in the history
  • Loading branch information
anbridge committed May 14, 2016
1 parent bbfe3e2 commit 3d0c40f
Show file tree
Hide file tree
Showing 57 changed files with 3,046 additions and 1,967 deletions.
57 changes: 1 addition & 56 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,4 @@
-cleaned up comments
-cleaned up some "test" files
-updated linux stuff
-rotation texture error (bird's eye):
-1 = top
-2 = bottom
-3 = west
-4 = east
-5 = north
-6 = south

## stole this from sledge. let's have a look at what this means

public void AlignTextureToWorld()
{
// Set the U and V axes to match the X, Y, or Z axes
// How they are calculated depends on which direction the plane is facing

var direction = Plane.GetClosestAxisToNormal();

// VHE behaviour:
// U axis: If the closest axis to the normal is the X axis,
// the U axis is UnitY. Otherwise, the U axis is UnitX.
// V axis: If the closest axis to the normal is the Z axis,
// the V axis is -UnitY. Otherwise, the V axis is -UnitZ.

Texture.UAxis = direction == Coordinate.UnitX ? Coordinate.UnitY : Coordinate.UnitX;
Texture.VAxis = direction == Coordinate.UnitZ ? -Coordinate.UnitY : -Coordinate.UnitZ;
Texture.Rotation = 0;

CalculateTextureCoordinates(true);
}
# what it references
## plane.get
public Coordinate GetClosestAxisToNormal()
{
// VHE prioritises the axes in order of X, Y, Z.
var norm = Normal.Absolute();

if (norm.X >= norm.Y && norm.X >= norm.Z) return Coordinate.UnitX; ##IF DISTANCE FROM X is grequal THAN Y AND Z furthest is X
if (norm.Y >= norm.Z) return Coordinate.UnitY;
return Coordinate.UnitZ;
}
### coordinate.unit x/y/z
public readonly static Coordinate UnitX = new Coordinate(1, 0, 0);
public readonly static Coordinate UnitY = new Coordinate(0, 1, 0);
public readonly static Coordinate UnitZ = new Coordinate(0, 0, 1);


FROM WHAT I GLEAM

the "normal" is the midpoint of a side. so if it's closest to the x axis, the uaxis variable will look like "uaxis" "[0 1 0 1] 0.25".
otherwise, it's "uaxis" "[-1 0 0 1] 0.25"

if the normal is closest to the Z axis, the vaxis variable is "uaxis" "[0 -1 0 1] 0.25". otherwise it's "uaxis" "[0 0 -1 1] 0.25"

what we can do to calculate the norm for each side is go through each variable side (each side is xyz1,xyz2,xyz3 and so on) and get the normal for each, then calculating what uaxis and vaxis should be used. I reckon the tough part might be replacing the u and vaxis variables in the string, but we can probably use a .replace() with a times replaced as 1. Also, that might be a bit tough since we don't know what exactly the uaxis/vaxis values are.

TO FIND THE NORMAL: http://tutorial.math.lamar.edu/Classes/CalcIII/EqnsOfPlanes.aspx
-FIXED TEXTURE BUG!! (praise allah!)
48 changes: 47 additions & 1 deletion createPrefab.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,41 @@ def createTile(posx, posy, id_num, world_id_num, entity_num, placeholder_list, r
"""
values = "".join(lines)#converting list to string
ogvalues = "".join(lines)
normal_list,axislist,negaxislist,vaxis,uaxis=[],['1 0 0 1','0 1 0 1','0 0 1 1'],['-1 0 0 1','0 -1 0 1','0 0 -1 1'],0,0
def evaluate(coords):
dist_x,dist_y,dist_z = abs(coords[0]),abs(coords[1]),abs(coords[2]),
if dist_x >= dist_y and dist_x >= dist_z:
return axislist[0]
if dist_y >= dist_z:
return axislist[1]
return axislist[2]
def get_normal(coord_list):
vector_a = (coord_list[1][0]-coord_list[0][0],coord_list[1][1]-coord_list[0][1],coord_list[1][2]-coord_list[0][2])
vector_b = (coord_list[2][0]-coord_list[0][0],coord_list[2][1]-coord_list[0][1],coord_list[2][2]-coord_list[0][2])
normal = (vector_a[1]*vector_b[2]-vector_a[2]*vector_b[1],vector_a[2]*vector_b[0]-vector_a[0]*vector_b[2],vector_a[0]*vector_b[1]-vector_a[1]*vector_b[0])
return normal
for normal_num in range(1,var_count+1,3):
normal_list=[]
for i in range(3):
normal_list.append([])
for var in ["x", "y", "z"]:
normal_list[i].append(eval(var+str(normal_num+i)))
coords = get_normal(normal_list)
response = evaluate(coords)
if response == axislist[0]:
uaxis = axislist[1]
else:
uaxis = axislist[0]
if response == axislist[2]:
vaxis = negaxislist[1]
else:
vaxis = negaxislist[2]
values = values.replace('AXIS_REPLACE_U',uaxis,1)
values = values.replace('AXIS_REPLACE_V',vaxis,1)
for i in range(ogvalues.count("world_idnum")):
values = values.replace('world_idnum', str(world_id_num), 1)
Expand Down Expand Up @@ -522,7 +557,18 @@ def createTile(posx, posy, id_num, world_id_num, entity_num, placeholder_list, r
elif letter == "\"":
eval(which_list).append(letter)

eval(which_list).insert(-2, "[1 0 0 1] 0.25")
eval(which_list).insert(-2, "[AXIS_REPLACE_U] 0.25")
elif "\"vaxis\"" in line:
quote_num = 0
for letter in line:
if letter == "\"":
quote_num += 1
if quote_num != 3:
eval(which_list).append(letter)
elif letter == "\"":
eval(which_list).append(letter)

eval(which_list).insert(-2, "[AXIS_REPLACE_U] 0.25")

else:
eval(which_list).append(line)
Expand Down
34 changes: 34 additions & 0 deletions prefab_template/add_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
normal_list,axislist,negaxislist,vaxis,uaxis=[],['1 0 0 1','0 1 0 1','0 0 1 1'],['-1 0 0 1','0 -1 0 1','0 0 -1 1'],0,0
def evaluate(coords):
dist_x,dist_y,dist_z = abs(coords[0]),abs(coords[1]),abs(coords[2]),
if dist_x >= dist_y and dist_x >= dist_z:
return axislist[0]
if dist_y >= dist_z:
return axislist[1]
return axislist[2]

def get_normal(coord_list):
vector_a = (coord_list[1][0]-coord_list[0][0],coord_list[1][1]-coord_list[0][1],coord_list[1][2]-coord_list[0][2])
vector_b = (coord_list[2][0]-coord_list[0][0],coord_list[2][1]-coord_list[0][1],coord_list[2][2]-coord_list[0][2])

normal = (vector_a[1]*vector_b[2]-vector_a[2]*vector_b[1],vector_a[2]*vector_b[0]-vector_a[0]*vector_b[2],vector_a[0]*vector_b[1]-vector_a[1]*vector_b[0])
return normal

for normal_num in range(1,var_count+1,3):
normal_list=[]
for i in range(3):
normal_list.append([])
for var in ["x", "y", "z"]:
normal_list[i].append(eval(var+str(normal_num+i)))
coords = get_normal(normal_list)
response = evaluate(coords)
if response == axislist[0]:
uaxis = axislist[1]
else:
uaxis = axislist[0]
if response == axislist[2]:
vaxis = negaxislist[1]
else:
vaxis = negaxislist[2]
values = values.replace('AXIS_REPLACE_U',uaxis,1)
values = values.replace('AXIS_REPLACE_V',vaxis,1)
Loading

0 comments on commit 3d0c40f

Please sign in to comment.