mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2025-01-10 23:15:14 +08:00
Improved mouse selection in collisions mode
This commit is contained in:
parent
e40e06896d
commit
786b9e5199
@ -272,6 +272,7 @@ namespace CodeWalker.GameFiles
|
|||||||
{
|
{
|
||||||
res.Hit = true;
|
res.Hit = true;
|
||||||
res.HitDist = testdist;
|
res.HitDist = testdist;
|
||||||
|
res.HitBounds = this;
|
||||||
res.Position = ray.Position + ray.Direction * testdist;
|
res.Position = ray.Position + ray.Direction * testdist;
|
||||||
res.Normal = Vector3.Normalize(res.Position - Center);
|
res.Normal = Vector3.Normalize(res.Position - Center);
|
||||||
res.Material.Type = MaterialIndex;
|
res.Material.Type = MaterialIndex;
|
||||||
@ -340,6 +341,7 @@ namespace CodeWalker.GameFiles
|
|||||||
{
|
{
|
||||||
res.Hit = true;
|
res.Hit = true;
|
||||||
res.HitDist = testdist;
|
res.HitDist = testdist;
|
||||||
|
res.HitBounds = this;
|
||||||
res.Position = ray.Position + ray.Direction * testdist;
|
res.Position = ray.Position + ray.Direction * testdist;
|
||||||
res.Normal = bcap.Normal(ref res.Position);
|
res.Normal = bcap.Normal(ref res.Position);
|
||||||
res.Material.Type = MaterialIndex;
|
res.Material.Type = MaterialIndex;
|
||||||
@ -392,6 +394,7 @@ namespace CodeWalker.GameFiles
|
|||||||
{ n = Vector3.UnitZ; } //ray starts inside the box...
|
{ n = Vector3.UnitZ; } //ray starts inside the box...
|
||||||
res.Hit = true;
|
res.Hit = true;
|
||||||
res.HitDist = testdist;
|
res.HitDist = testdist;
|
||||||
|
res.HitBounds = this;
|
||||||
res.Position = hpt;
|
res.Position = hpt;
|
||||||
res.Normal = n;
|
res.Normal = n;
|
||||||
res.Material.Type = MaterialIndex;
|
res.Material.Type = MaterialIndex;
|
||||||
@ -461,6 +464,7 @@ namespace CodeWalker.GameFiles
|
|||||||
{
|
{
|
||||||
res.Hit = true;
|
res.Hit = true;
|
||||||
res.HitDist = testdist;
|
res.HitDist = testdist;
|
||||||
|
res.HitBounds = this;
|
||||||
res.Position = ray.Position + ray.Direction * testdist;
|
res.Position = ray.Position + ray.Direction * testdist;
|
||||||
res.Normal = n;
|
res.Normal = n;
|
||||||
res.Material.Type = MaterialIndex;
|
res.Material.Type = MaterialIndex;
|
||||||
@ -533,6 +537,7 @@ namespace CodeWalker.GameFiles
|
|||||||
{
|
{
|
||||||
res.Hit = true;
|
res.Hit = true;
|
||||||
res.HitDist = testdist;
|
res.HitDist = testdist;
|
||||||
|
res.HitBounds = this;
|
||||||
res.Position = ray.Position + ray.Direction * testdist;
|
res.Position = ray.Position + ray.Direction * testdist;
|
||||||
res.Normal = n;
|
res.Normal = n;
|
||||||
res.Material.Type = MaterialIndex;
|
res.Material.Type = MaterialIndex;
|
||||||
@ -1125,6 +1130,7 @@ namespace CodeWalker.GameFiles
|
|||||||
res.Hit = true;
|
res.Hit = true;
|
||||||
res.Normal = n1;
|
res.Normal = n1;
|
||||||
res.HitPolygon = polygon;
|
res.HitPolygon = polygon;
|
||||||
|
res.HitBounds = this;
|
||||||
|
|
||||||
byte matind = ((PolygonMaterialIndices != null) && (p < PolygonMaterialIndices.Length)) ? PolygonMaterialIndices[p] : (byte)0;
|
byte matind = ((PolygonMaterialIndices != null) && (p < PolygonMaterialIndices.Length)) ? PolygonMaterialIndices[p] : (byte)0;
|
||||||
BoundMaterial_s mat = ((Materials != null) && (matind < Materials.Length)) ? Materials[matind] : new BoundMaterial_s();
|
BoundMaterial_s mat = ((Materials != null) && (matind < Materials.Length)) ? Materials[matind] : new BoundMaterial_s();
|
||||||
|
@ -1106,6 +1106,10 @@ namespace CodeWalker.World
|
|||||||
|
|
||||||
var b = ybn.Bounds;
|
var b = ybn.Bounds;
|
||||||
var bhit = b.RayIntersect(ref ray, res.HitDist);
|
var bhit = b.RayIntersect(ref ray, res.HitDist);
|
||||||
|
if (bhit.Hit)
|
||||||
|
{
|
||||||
|
bhit.HitYbn = ybn;
|
||||||
|
}
|
||||||
res.TryUpdate(ref bhit);
|
res.TryUpdate(ref bhit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1225,6 +1229,10 @@ namespace CodeWalker.World
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (res.Hit)
|
||||||
|
{
|
||||||
|
res.HitEntity = ent;
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -1249,6 +1257,8 @@ namespace CodeWalker.World
|
|||||||
var ihit = ybn.Bounds.RayIntersect(ref iray, res.HitDist);
|
var ihit = ybn.Bounds.RayIntersect(ref iray, res.HitDist);
|
||||||
if (ihit.Hit)
|
if (ihit.Hit)
|
||||||
{
|
{
|
||||||
|
ihit.HitYbn = ybn;
|
||||||
|
ihit.HitEntity = mlo;
|
||||||
ihit.Position = iori.Multiply(ihit.Position) + mlo.Position;
|
ihit.Position = iori.Multiply(ihit.Position) + mlo.Position;
|
||||||
ihit.Normal = iori.Multiply(ihit.Normal);
|
ihit.Normal = iori.Multiply(ihit.Normal);
|
||||||
}
|
}
|
||||||
@ -2141,6 +2151,9 @@ namespace CodeWalker.World
|
|||||||
public bool Hit;
|
public bool Hit;
|
||||||
public float HitDist;
|
public float HitDist;
|
||||||
public BoundPolygon HitPolygon;
|
public BoundPolygon HitPolygon;
|
||||||
|
public Bounds HitBounds;
|
||||||
|
public YbnFile HitYbn;
|
||||||
|
public YmapEntityDef HitEntity;
|
||||||
public Vector3 Position;
|
public Vector3 Position;
|
||||||
public Vector3 Normal;
|
public Vector3 Normal;
|
||||||
public int TestedNodeCount;
|
public int TestedNodeCount;
|
||||||
@ -2155,6 +2168,9 @@ namespace CodeWalker.World
|
|||||||
Hit = true;
|
Hit = true;
|
||||||
HitDist = r.HitDist;
|
HitDist = r.HitDist;
|
||||||
HitPolygon = r.HitPolygon;
|
HitPolygon = r.HitPolygon;
|
||||||
|
HitBounds = r.HitBounds;
|
||||||
|
HitYbn = r.HitYbn;
|
||||||
|
HitEntity = r.HitEntity;
|
||||||
Material = r.Material;
|
Material = r.Material;
|
||||||
Position = r.Position;
|
Position = r.Position;
|
||||||
Normal = r.Normal;
|
Normal = r.Normal;
|
||||||
|
58
WorldForm.cs
58
WorldForm.cs
@ -442,7 +442,7 @@ namespace CodeWalker
|
|||||||
RenderSingleItem();
|
RenderSingleItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMouseHitsFromRenderer();
|
UpdateMouseHits();
|
||||||
|
|
||||||
RenderSelection();
|
RenderSelection();
|
||||||
|
|
||||||
@ -2203,8 +2203,8 @@ namespace CodeWalker
|
|||||||
//reset variables for beginning the mouse hit test
|
//reset variables for beginning the mouse hit test
|
||||||
CurMouseHit.Clear();
|
CurMouseHit.Clear();
|
||||||
|
|
||||||
// Get whether or not we can brush from the project form.
|
|
||||||
if (Input.CtrlPressed && ProjectForm != null && ProjectForm.CanPaintInstances())
|
if (Input.CtrlPressed && ProjectForm != null && ProjectForm.CanPaintInstances()) // Get whether or not we can brush from the project form.
|
||||||
{
|
{
|
||||||
ControlBrushEnabled = true;
|
ControlBrushEnabled = true;
|
||||||
MouseRayCollisionVisible = false;
|
MouseRayCollisionVisible = false;
|
||||||
@ -2253,16 +2253,62 @@ namespace CodeWalker
|
|||||||
return space.RayIntersect(ray, float.MaxValue, collisionmeshlayers);
|
return space.RayIntersect(ray, float.MaxValue, collisionmeshlayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateMouseHits()
|
||||||
|
{
|
||||||
|
UpdateMouseHitsFromRenderer();
|
||||||
|
UpdateMouseHitsFromSpace();
|
||||||
|
}
|
||||||
private void UpdateMouseHitsFromRenderer()
|
private void UpdateMouseHitsFromRenderer()
|
||||||
{
|
{
|
||||||
foreach (var rd in Renderer.RenderedDrawables)
|
foreach (var rd in Renderer.RenderedDrawables)
|
||||||
{
|
{
|
||||||
UpdateMouseHits(rd.Drawable, rd.Archetype, rd.Entity);
|
UpdateMouseHits(rd.Drawable, rd.Archetype, rd.Entity);
|
||||||
}
|
}
|
||||||
foreach (var rb in Renderer.RenderedBoundComps)
|
//foreach (var rb in Renderer.RenderedBoundComps)
|
||||||
{
|
//{
|
||||||
UpdateMouseHits(rb.BoundComp, rb.Entity);
|
// UpdateMouseHits(rb.BoundComp, rb.Entity);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
private void UpdateMouseHitsFromSpace()
|
||||||
|
{
|
||||||
|
if (SelectionMode == MapSelectionMode.Collision)
|
||||||
|
{
|
||||||
|
MouseRayCollision = GetSpaceMouseRay();
|
||||||
|
|
||||||
|
if (MouseRayCollision.Hit)
|
||||||
|
{
|
||||||
|
Matrix rmat = MouseRayCollision.HitBounds?.Transform ?? Matrix.Identity;
|
||||||
|
rmat.TranslationVector = Vector3.Zero;
|
||||||
|
|
||||||
|
var position = MouseRayCollision.HitEntity?.Position ?? Vector3.Zero;
|
||||||
|
var orientation = MouseRayCollision.HitEntity?.Orientation ?? Quaternion.Identity;
|
||||||
|
var scale = MouseRayCollision.HitEntity?.Scale ?? Vector3.One;
|
||||||
|
var camrel = position - camera.Position;
|
||||||
|
var trans = MouseRayCollision.HitBounds?.Transform.TranslationVector ?? Vector3.Zero;
|
||||||
|
|
||||||
|
CurMouseHit.CollisionBounds = MouseRayCollision.HitBounds;
|
||||||
|
CurMouseHit.EntityDef = MouseRayCollision.HitEntity;
|
||||||
|
CurMouseHit.Archetype = MouseRayCollision.HitEntity?.Archetype;
|
||||||
|
CurMouseHit.HitDist = MouseRayCollision.HitDist;
|
||||||
|
CurMouseHit.CamRel = camrel + orientation.Multiply(trans);
|
||||||
|
CurMouseHit.BBOffset = trans;
|
||||||
|
CurMouseHit.BBOrientation = Quaternion.RotationMatrix(rmat);
|
||||||
|
CurMouseHit.AABB = new BoundingBox(MouseRayCollision.HitBounds?.BoundingBoxMin ?? Vector3.Zero, MouseRayCollision.HitBounds?.BoundingBoxMax ?? Vector3.Zero);
|
||||||
|
|
||||||
|
|
||||||
|
MapBox mb = new MapBox();
|
||||||
|
mb.CamRelPos = MouseRayCollision.Position - camera.Position;
|
||||||
|
mb.Orientation = Quaternion.Identity;
|
||||||
|
mb.Scale = Vector3.One;
|
||||||
|
mb.BBMin = new Vector3(-0.01f);
|
||||||
|
mb.BBMax = new Vector3(+0.01f);
|
||||||
|
Renderer.BoundingBoxes.Add(mb);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void UpdateMouseHits(DrawableBase drawable, Archetype arche, YmapEntityDef entity)
|
private void UpdateMouseHits(DrawableBase drawable, Archetype arche, YmapEntityDef entity)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user