very much working
This commit is contained in:
@@ -135,4 +135,85 @@
|
||||
( 576 423.59797974644664 257.65685424949243 ) ( 577 423.59797974644664 257.65685424949243 ) ( 576 422.89087296526009 258.36396103067898 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 576 434.91168824543138 268.97056274847722 ) ( 576 434.20458146424482 269.67766952966372 ) ( 576 435.61879502661793 269.67766952966377 ) common/slick 0 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 15
|
||||
{
|
||||
( 576 384 114.74516600406101 ) ( 576 384.70710744499939 115.45227279578421 ) ( 576 383.29289388262629 115.45227277471085 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 560 384 114.74516600406101 ) ( 560 383.29289388262629 115.45227277471085 ) ( 561 384 114.74516600406101 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 640 395.31370765604777 216.56854266351127 ) ( 640 396.0208144266976 217.27564945523451 ) ( 641 395.31370765604777 216.56854266351127 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 560 384 114.74516600406101 ) ( 561 384 114.74516600406101 ) ( 560 384.70710744499939 115.45227279578421 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 640 423.59797966215297 165.65685483954832 ) ( 641 423.59797966215297 165.65685483954832 ) ( 640 422.89087287042969 166.36396161019815 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 640 434.9116879925503 176.97056350712049 ) ( 640 434.20458120082702 177.67767027777029 ) ( 640 435.61879476320013 177.67767029884376 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 16
|
||||
{
|
||||
( 304 616 0 ) ( 304 617 0 ) ( 304 616 1 ) common/slick -24 0 0 -1 1 0 0 0
|
||||
( 304 616 0 ) ( 304 616 1 ) ( 305 616 0 ) common/slick 16 0 0 1 1 0 0 0
|
||||
( 304 616 0 ) ( 305 616 0 ) ( 304 617 0 ) common/slick 16 24 0 1 -1 0 0 0
|
||||
( 368 680 64 ) ( 368 681 64 ) ( 369 680 64 ) common/slick 16 -24 0 1 1 0 0 0
|
||||
( 368 680 16 ) ( 369 680 16 ) ( 368 680 17 ) common/slick -16 0 0 -1 1 0 0 0
|
||||
( 368 680 16 ) ( 368 680 17 ) ( 368 681 16 ) common/slick 24 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 17
|
||||
{
|
||||
( 512 579.15681763943235 114.8554045051751 ) ( 512 579.81287732988358 115.61011414221409 ) ( 512 578.40210872214027 115.5114635699598 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 576 583.34012597177184 217.21994888776575 ) ( 576 583.99618498951622 217.97465847776454 ) ( 577 583.34012597177184 217.21994888776575 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 496 579.15681763943235 114.8554045051751 ) ( 496 578.40210872214027 115.5114635699598 ) ( 497 579.15681763943235 114.8554045051751 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 576 615.10691872779398 168.40529045409508 ) ( 577 615.10691872779398 168.40529045409508 ) ( 576 614.35220913779528 169.06134947183955 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 496 579.15681763943235 114.8554045051751 ) ( 497 579.15681763943235 114.8554045051751 ) ( 496 579.81287732988358 115.61011414221409 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 576 625.60386301170536 180.48064389407614 ) ( 576 624.84915342170666 181.13670291182055 ) ( 576 626.25992202944997 181.23535348407492 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 18
|
||||
{
|
||||
( 576 577.57937092981342 114.77273402618664 ) ( 576 578.26136995291665 115.50408776150277 ) ( 576 576.84801789197036 115.45473239888557 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 640 585.33260198287928 216.92892533878683 ) ( 640 586.01460033204376 217.66027905056853 ) ( 641 585.33260198287928 216.92892533878683 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 560 577.57937092981342 114.77273402618664 ) ( 560 576.84801789197036 115.45473239888557 ) ( 561 577.57937092981342 114.77273402618664 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 640 615.37643625602493 167.03535839706817 ) ( 641 615.37643625602493 167.03535839706817 ) ( 640 614.64508254424322 167.71735674623267 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 560 577.57937092981342 114.77273402618664 ) ( 561 577.57937092981342 114.77273402618664 ) ( 560 578.26136995291665 115.50408776150277 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 640 626.28840984265662 178.737017785576 ) ( 640 625.55705613087491 179.41901613474045 ) ( 640 626.97040819182121 179.46837149735774 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 19
|
||||
{
|
||||
( 704 576 114.74516600406101 ) ( 704 576.70710744499934 115.45227279578421 ) ( 704 575.29289388262623 115.45227277471085 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 688 576 114.74516600406101 ) ( 688 575.29289388262623 115.45227277471085 ) ( 689 576 114.74516600406101 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 768 587.31370765604777 216.56854266351127 ) ( 768 588.0208144266976 217.27564945523451 ) ( 769 587.31370765604777 216.56854266351127 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 688 576 114.74516600406101 ) ( 689 576 114.74516600406101 ) ( 688 576.70710744499934 115.45227279578421 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 768 615.59797966215297 165.65685483954832 ) ( 769 615.59797966215297 165.65685483954832 ) ( 768 614.89087287042969 166.36396161019815 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 768 626.91168799255024 176.97056350712049 ) ( 768 626.20458120082708 177.67767027777029 ) ( 768 627.61879476320019 177.67767029884376 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 20
|
||||
{
|
||||
( 832 574.42062907018658 114.77273402618667 ) ( 832 575.15198343558188 115.45473237361267 ) ( 832 573.73863137316471 115.50408769410882 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 816 574.42062907018658 114.77273402618667 ) ( 816 573.73863137316471 115.50408769410882 ) ( 817 574.42062907018658 114.77273402618667 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 896 589.28102931918045 216.13923993271624 ) ( 896 590.012383010637 216.82123830367675 ) ( 897 589.28102931918045 216.13923993271624 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 816 574.42062907018658 114.77273402618667 ) ( 817 574.42062907018658 114.77273402618667 ) ( 816 575.15198343558188 115.45473237361267 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 896 615.77127902966379 164.2714592757782 ) ( 897 615.77127902966379 164.2714592757782 ) ( 896 615.08928065870327 165.00281296723477 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 896 627.47293809296934 175.18343321114648 ) ( 896 626.79093972200883 175.91478690260305 ) ( 896 628.204291784426 175.86543158210702 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 21
|
||||
{
|
||||
( 896 572.84318236056765 114.85540450517516 ) ( 896 573.59789260372122 115.51146349837141 ) ( 896 572.18712399303786 115.61011402858165 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 880 572.84318236056765 114.85540450517516 ) ( 880 572.18712399303786 115.61011402858165 ) ( 881 572.84318236056765 114.85540450517516 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 960 591.23217009387338 215.6415401856502 ) ( 960 591.98687966431999 216.29759922588676 ) ( 961 591.23217009387338 215.6415401856502 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 880 572.84318236056765 114.85540450517516 ) ( 881 572.84318236056765 114.85540450517516 ) ( 880 573.59789260372122 115.51146349837141 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 960 615.89612321997288 162.88085959684838 ) ( 961 615.89612321997288 162.88085959684838 ) ( 960 615.24006417973635 163.6355691672951 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 960 627.97147634712042 173.37780424063328 ) ( 960 627.31541730688389 174.13251381108 ) ( 960 628.72618591756725 174.03386328086987 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 22
|
||||
{
|
||||
( 768 575.21019424385111 114.7520585344753 ) ( 768 575.92953470808527 115.44671690388421 ) ( 768 574.51553653691985 115.47139831269372 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 752 575.21019424385111 114.7520585344753 ) ( 752 574.51553653691985 115.47139831269372 ) ( 753 575.21019424385111 114.7520585344753 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 832 588.29924172170092 216.36247557614178 ) ( 832 589.01858151168835 217.05713395731976 ) ( 833 588.29924172170092 216.36247557614178 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 752 575.21019424385111 114.7520585344753 ) ( 753 575.21019424385111 114.7520585344753 ) ( 752 575.92953470808527 115.44671690388421 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 832 615.69067442786979 164.96491323799748 ) ( 833 615.69067442786979 164.96491323799748 ) ( 832 614.99601604669181 165.68425302798491 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 832 627.20011106766867 176.07944733684542 ) ( 832 626.5054526864908 176.79878712683285 ) ( 832 627.91945085765622 176.77410571802343 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
// brush 23
|
||||
{
|
||||
( 640 576.78980575614889 114.7520585344753 ) ( 640 577.48446479013558 115.47139835693415 ) ( 640 576.07046661970571 115.44671690598433 ) common/slick -32 0 0 -1 1 0 0 0
|
||||
( 704 586.32472732544409 216.75737842479367 ) ( 704 587.01938568518403 217.47671823548353 ) ( 705 586.32472732544409 216.75737842479367 ) common/slick 0 0 0 1 1 0 0 0
|
||||
( 624 576.78980575614889 114.7520585344753 ) ( 624 576.07046661970571 115.44671690598433 ) ( 625 576.78980575614889 114.7520585344753 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 704 615.49322296823664 166.34707330831586 ) ( 705 615.49322296823664 166.34707330831586 ) ( 704 614.77388315754672 167.04173166805586 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 624 576.78980575614889 114.7520585344753 ) ( 625 576.78980575614889 114.7520585344753 ) ( 624 577.48446479013558 115.47139835693415 ) common/slick 0 0 180 1 1 0 0 0
|
||||
( 704 626.60775672407669 177.85651027935376 ) ( 704 625.88841691338689 178.5511686390937 ) ( 704 627.30241508381675 178.57585009004364 ) common/slick -32 0 0 1 1 0 0 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1136,8 +1136,14 @@ namespace Game
|
||||
|
||||
private List<Vector3> debugPoints = new List<Vector3>();
|
||||
|
||||
private List<Tuple<Vector3, Vector3>> debugNormals = new List<Tuple<Vector3, Vector3>>();
|
||||
|
||||
public override void OnDebugDraw()
|
||||
{
|
||||
foreach (var cn in debugNormals)
|
||||
{
|
||||
DebugDraw.DrawLine(cn.Item1, cn.Item1 + cn.Item2 * 50f, Color.Red, 0f, false);
|
||||
}
|
||||
return;
|
||||
if (root == null)
|
||||
return;
|
||||
@@ -1433,14 +1439,14 @@ namespace Game
|
||||
|
||||
Vector3[] cubePoints = new[]
|
||||
{
|
||||
new Vector3(-cs, -cs, -cs),
|
||||
new Vector3(cs, -cs, -cs),
|
||||
new Vector3(-cs, cs, -cs),
|
||||
new Vector3(cs, cs, -cs),
|
||||
new Vector3(-cs, -cs, cs),
|
||||
new Vector3(cs, -cs, cs),
|
||||
new Vector3(-cs, cs, cs),
|
||||
new Vector3(cs, cs, cs),
|
||||
new Vector3(-1, -1, -1) * cs,
|
||||
new Vector3(1, -1, -1) * cs,
|
||||
new Vector3(-1, 1, -1) * cs,
|
||||
new Vector3(1, 1, -1) * cs,
|
||||
new Vector3(-1, -1, 1) * cs,
|
||||
new Vector3(1, -1, 1) * cs,
|
||||
new Vector3(-1, 1, 1) * cs,
|
||||
new Vector3(1, 1, 1) * cs,
|
||||
};
|
||||
Vector3[] cubeVerts;
|
||||
QuickHull(cubePoints, out cubeVerts);
|
||||
@@ -1655,49 +1661,6 @@ namespace Game
|
||||
}
|
||||
|
||||
asdf++;
|
||||
|
||||
/*var newMeshPoints = new List<Vector3>();
|
||||
int duplis = 0;
|
||||
foreach (var v in faceVertices)
|
||||
{
|
||||
bool found = false;
|
||||
foreach (var vo in newMeshPoints)
|
||||
{
|
||||
if ((v - vo).Length < epsilon)
|
||||
{
|
||||
found = true;
|
||||
duplis++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//if (!newMeshPoints.Contains(v))
|
||||
if (!found)
|
||||
newMeshPoints.Add(v);
|
||||
}
|
||||
if (duplis > 0)
|
||||
Console.Print("duplicates: " + duplis);
|
||||
|
||||
if (newMeshPoints.Count > 0)
|
||||
{
|
||||
var tempPoints = newMeshPoints;
|
||||
newMeshPoints = new List<Vector3>(tempPoints.Count);
|
||||
foreach (var tp in tempPoints)
|
||||
{
|
||||
// Flip Y and Z
|
||||
newMeshPoints.Add(new Vector3(tp.X, tp.Z, tp.Y));
|
||||
}
|
||||
|
||||
var hullPoints = QuickHull(newMeshPoints.ToArray());
|
||||
var ms = new MeshSimplifier();
|
||||
var optimizedVerts = ms.Simplify(hullPoints);
|
||||
brushVertices.Clear();
|
||||
brushVertices.AddRange(hullPoints);
|
||||
}
|
||||
else
|
||||
brushVertices.Clear();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
vertices = brushVertices.ToArray();
|
||||
@@ -1715,7 +1678,6 @@ namespace Game
|
||||
if (true)
|
||||
{
|
||||
int brushIndex = 0;
|
||||
//foreach (var brush in root.entities[0].brushes.Skip(1).Take(1))
|
||||
foreach (var brush in root.entities[0].brushes)
|
||||
{
|
||||
try
|
||||
@@ -1726,9 +1688,6 @@ namespace Game
|
||||
Vector2[] brushUvs = new Vector2[brushVertices.Length];
|
||||
Vector3[] brushNormals = new Vector3[brushVertices.Length];
|
||||
|
||||
Vector2[] brushScaling = new Vector2[brushVertices.Length];
|
||||
|
||||
|
||||
for (int i=0; i<brushVertices.Length; i+=3)
|
||||
{
|
||||
Vector3 v1 = brushVertices[i+0];
|
||||
@@ -1737,9 +1696,7 @@ namespace Game
|
||||
|
||||
Vector3 normal = -Vector3.Cross(v3 - v1, v2 - v1).Normalized;
|
||||
|
||||
|
||||
|
||||
|
||||
// fetch the texture parameters from the plane with matching normal
|
||||
Vector2 uvScale = new Vector2(0f);
|
||||
float uvRotation = 0f;
|
||||
Vector2 uvOffset = new Vector2(0f);
|
||||
@@ -1747,10 +1704,9 @@ namespace Game
|
||||
Vector2 textureSize = new Vector2(64f); // TODO: figure out the correct size for the material
|
||||
foreach (var brushPlane in brush.planes)
|
||||
{
|
||||
Plane plane = brushPlane.plane;
|
||||
if ((plane.Normal - normal).Length < 0.01f)
|
||||
if ((brushPlane.plane.Normal - normal).Length < 0.01f)
|
||||
{
|
||||
normal = plane.Normal; // for consistency
|
||||
normal = brushPlane.plane.Normal; // for consistency
|
||||
uvScale = 1f / brushPlane.scale / textureSize; // texture size?
|
||||
uvRotation = brushPlane.rotation;
|
||||
uvOffset = brushPlane.offset * brushPlane.scale;
|
||||
@@ -1759,55 +1715,55 @@ namespace Game
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
Console.Print("no found, bad geometry?");
|
||||
Console.Print("no matching plane found, bad geometry?");
|
||||
|
||||
// texture is projected to the surface from the closest axis
|
||||
|
||||
Vector3 normal2 = normal;
|
||||
List<Tuple<float, Vector3>> dots = new List<Tuple<float, Vector3>>(new []
|
||||
Vector2 uv1, uv2, uv3;
|
||||
// if quake format
|
||||
{
|
||||
new Tuple<float, Vector3>(Mathf.Abs(Vector3.Dot(normal2, Vector3.Right)), Vector3.Right),
|
||||
new Tuple<float, Vector3>(Mathf.Abs(Vector3.Dot(normal2, Vector3.Forward)), -Vector3.Forward),
|
||||
// The texture is projected to the surface from three angles, the axis with least
|
||||
// distortion is chosen here.
|
||||
|
||||
new Tuple<float, Vector3>(Mathf.Abs(Vector3.Dot(normal2, Vector3.Up)), -Vector3.Up),
|
||||
// Attempt to workaround most rounding errors at 45-degree angles which causes bias towards one axis.
|
||||
// This behaviour is seemingly random in different engines and editors, so let's not bother.
|
||||
Vector3 textureNormal = new Vector3((float)Math.Round(normal.X, 4),
|
||||
(float)Math.Round(normal.Y, 4), (float)Math.Round(normal.Z, 4));
|
||||
|
||||
});
|
||||
dots.Sort((l, r) => l.Item1.CompareTo(r.Item1));
|
||||
Vector3 theUp = dots.Last().Item2;
|
||||
var dotX = Math.Abs(Vector3.Dot(textureNormal, Vector3.Right));
|
||||
var dotY = Math.Abs(Vector3.Dot(textureNormal, Vector3.Up));
|
||||
var dotZ = Math.Abs(Vector3.Dot(textureNormal, Vector3.Forward));
|
||||
|
||||
/*var dotX = Mathf.Abs(Vector3.Dot(normal2, Vector3.Right));
|
||||
var dotY = Mathf.Abs(Vector3.Dot(normal2, Vector3.Up));
|
||||
var dotZ = Mathf.Abs(Vector3.Dot(normal2, Vector3.Forward));
|
||||
Vector3 theUp;
|
||||
if (false)
|
||||
{}
|
||||
else if (dotY > dotX && dotY > dotZ)
|
||||
theUp = -Vector3.Up;
|
||||
else if (dotX > dotY && dotX > dotZ)
|
||||
theUp = Vector3.Right;
|
||||
else if (dotZ > dotX && dotZ > dotY)
|
||||
theUp = -Vector3.Forward;
|
||||
else
|
||||
theUp = Vector3.Right;*/
|
||||
Vector3 axis;
|
||||
if (dotY >= dotX && dotY >= dotZ)
|
||||
axis = -Vector3.Up;
|
||||
else if (dotX >= dotY && dotX >= dotZ)
|
||||
axis = Vector3.Right;
|
||||
else if (dotZ >= dotX && dotZ >= dotY)
|
||||
axis = -Vector3.Forward;
|
||||
else
|
||||
axis = Vector3.Right;
|
||||
|
||||
var up1 = Vector3.Up;
|
||||
var up2 = -Vector3.Forward;
|
||||
var axisForward = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
|
||||
? -Vector3.Forward
|
||||
: Vector3.Up;
|
||||
var axisForward2 = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
|
||||
? Vector3.Up
|
||||
: -Vector3.Forward;
|
||||
|
||||
var finalUp = Mathf.Abs(Vector3.Dot(theUp, up1)) > 0.01f ? up2 : up1;
|
||||
var finalUp2 = Mathf.Abs(Vector3.Dot(theUp, up1)) > 0.01f ? up1 : up2;
|
||||
var theRight = Vector3.Right;
|
||||
Quaternion rot = Quaternion.Identity;
|
||||
rot = rot * Quaternion.LookRotation(theUp, finalUp);
|
||||
rot = rot * Quaternion.RotationAxis(up2, 180f * Mathf.DegreesToRadians);
|
||||
rot = rot * Quaternion.RotationAxis(Mathf.Abs(Vector3.Dot(theUp, theRight)) > 0.01f ? theRight : finalUp2, uvRotation * Mathf.DegreesToRadians);
|
||||
Quaternion rot = Quaternion.Identity;
|
||||
rot = rot * Quaternion.LookRotation(axis, axisForward);
|
||||
rot = rot * Quaternion.RotationAxis(-Vector3.Forward, 180f * Mathf.DegreesToRadians);
|
||||
rot = rot * Quaternion.RotationAxis(
|
||||
Mathf.Abs(Vector3.Dot(axis, Vector3.Right)) > 0.01f ? Vector3.Right : axisForward2,
|
||||
uvRotation * Mathf.DegreesToRadians);
|
||||
|
||||
//if (Mathf.Abs(Vector3.Dot(theUp, theRight)) <= 0.01f)
|
||||
// uvOffset *= 2;
|
||||
uv1 = ((Vector2)(v1 * rot) + uvOffset) * uvScale;
|
||||
uv2 = ((Vector2)(v2 * rot) + uvOffset) * uvScale;
|
||||
uv3 = ((Vector2)(v3 * rot) + uvOffset) * uvScale;
|
||||
}
|
||||
|
||||
|
||||
brushUvs[i + 0] = ((Vector2)(v1 * rot) + (uvOffset)) * uvScale;
|
||||
brushUvs[i + 1] = ((Vector2)(v2 * rot) + (uvOffset)) * uvScale;
|
||||
brushUvs[i + 2] = ((Vector2)(v3 * rot) + (uvOffset)) * uvScale;
|
||||
brushUvs[i + 0] = uv1;
|
||||
brushUvs[i + 1] = uv2;
|
||||
brushUvs[i + 2] = uv3;
|
||||
|
||||
brushNormals[i + 0] = normal;
|
||||
brushNormals[i + 1] = normal;
|
||||
|
||||
Reference in New Issue
Block a user