mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-25 16:32:55 +08:00
Merge pull request #204 from coltfox/bvh-extents-calc
Correctly calculate BVH item extents
This commit is contained in:
commit
378e66ef3b
@ -2880,7 +2880,7 @@ namespace CodeWalker.GameFiles
|
|||||||
if (child != null)
|
if (child != null)
|
||||||
{
|
{
|
||||||
var cbox = new BoundingBox(child.BoxMin, child.BoxMax);
|
var cbox = new BoundingBox(child.BoxMin, child.BoxMax);
|
||||||
var tcbox = cbox.Transform(child.Position, child.Orientation, child.Scale);
|
var tcbox = cbox.Transform(child.Transform);
|
||||||
var it = new BVHBuilderItem();
|
var it = new BVHBuilderItem();
|
||||||
it.Min = tcbox.Minimum;
|
it.Min = tcbox.Minimum;
|
||||||
it.Max = tcbox.Maximum;
|
it.Max = tcbox.Maximum;
|
||||||
@ -2894,16 +2894,7 @@ namespace CodeWalker.GameFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var bvh = BVHBuilder.Build(items, 1); //composites have BVH item threshold of 1
|
BVH = BVHBuilder.Build(items, 1); //composites have BVH item threshold of 1
|
||||||
|
|
||||||
BoxMin = bvh.BoundingBoxMin.XYZ();
|
|
||||||
BoxMax = bvh.BoundingBoxMax.XYZ();
|
|
||||||
BoxCenter = bvh.BoundingBoxCenter.XYZ();
|
|
||||||
SphereCenter = BoxCenter;
|
|
||||||
SphereRadius = (BoxMax - BoxCenter).Length();
|
|
||||||
|
|
||||||
BVH = bvh;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateChildrenFlags()
|
public void UpdateChildrenFlags()
|
||||||
|
@ -127,6 +127,11 @@ namespace CodeWalker
|
|||||||
public static BoundingBox Transform(this BoundingBox b, Vector3 position, Quaternion orientation, Vector3 scale)
|
public static BoundingBox Transform(this BoundingBox b, Vector3 position, Quaternion orientation, Vector3 scale)
|
||||||
{
|
{
|
||||||
var mat = Matrix.Transformation(Vector3.Zero, Quaternion.Identity, scale, Vector3.Zero, orientation, position);
|
var mat = Matrix.Transformation(Vector3.Zero, Quaternion.Identity, scale, Vector3.Zero, orientation, position);
|
||||||
|
return b.Transform(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BoundingBox Transform(this BoundingBox b, Matrix mat)
|
||||||
|
{
|
||||||
var matabs = mat;
|
var matabs = mat;
|
||||||
matabs.Column1 = mat.Column1.Abs();
|
matabs.Column1 = mat.Column1.Abs();
|
||||||
matabs.Column2 = mat.Column2.Abs();
|
matabs.Column2 = mat.Column2.Abs();
|
||||||
|
Loading…
Reference in New Issue
Block a user