// ---------------------------------------------------------------------------------------------- // -- BoundingMetaMesh -------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------- public static bool Intersect(Ray a, BoundingMetaMesh b, out object intersection) { var r = new Common.RayIntersection(); intersection = r; Matrix invTransformation = Matrix.Invert(b.Transformation); var newRay = new Ray( Vector3.TransformCoordinate(a.Position, invTransformation), Vector3.Normalize(Vector3.TransformNormal(a.Direction, invTransformation))); if (b.XMesh != null) { #if BOUNDING_META_MESH_REAQUIRE_ON_DISPOSED if (b.XMesh.Disposed) { b.Init(content); } #endif if (!b.XMesh.Intersects(newRay, out r.Distance)) { return(false); } } else if (b.Mesh != null) { var mesh = content.Peek <SlimDX.Direct3D9.Mesh>(b.Mesh); if (!mesh.Intersects(newRay, out r.Distance)) { return(false); } } else if (b.SoftwareMesh != null) { Vector2 uv; Graphics.Software.Triangle triangle; if (!b.SoftwareMesh.Intersect(newRay, false, out triangle, out r.Distance, out uv)) { return(false); } } else if (b.SkinnedMeshInstance != null) { newRay = a; var sm = content.Peek <Renderer.Renderer.EntityAnimation>(b.SkinnedMeshInstance); object o; if (!Intersect(newRay, sm, out o)) { return(false); } r = (Common.RayIntersection)o; } var newPos = Vector3.TransformCoordinate(newRay.Position + newRay.Direction * r.Distance, b.Transformation); r.Distance = (newPos - a.Position).Length(); return(true); }
public override StructBoxer <BoundingBox> Construct(MetaModel metaResource, ContentPool content) { BoundingBox b = new BoundingBox(); if (content.Device9 != null) { var m = content.Peek <Model9>(metaResource); if (m != null) { if (m.SkinnedMesh != null) { b = Common.Boundings.Transform(m.SkinnedMesh.Bounding, metaResource.World); } else if (m.XMesh != null) { b = Common.Boundings.Transform(Common.Boundings.BoundingBoxFromXMesh(m.XMesh), metaResource.World); } } } else { throw new NotImplementedException(); } return(new StructBoxer <BoundingBox> { Value = b }); }
public override StructBoxer <BoundingBox> Construct(MeshFromFile metaResource, ContentPool content) { var mesh = content.Peek <SlimDX.Direct3D9.Mesh>(metaResource); return(new StructBoxer <BoundingBox> { Value = Common.Boundings.BoundingBoxFromXMesh(mesh) }); }
public override StructBoxer <BoundingBox> Construct(SkinnedMeshFromFile metaResource, ContentPool content) { var mesh = content.Peek <SkinnedMesh>(metaResource); return(new StructBoxer <BoundingBox> { Value = mesh.Bounding }); }
public override Software.Mesh Construct(MeshConcretize metaResource, ContentPool content) { if (metaResource.XMesh != null) { return(new Graphics.Software.Mesh(metaResource.XMesh)); } else if (metaResource.MetaXMesh != null) { var mesh = content.Peek <SlimDX.Direct3D9.Mesh>(metaResource.MetaXMesh); return(new Graphics.Software.Mesh(mesh)); } return(metaResource.GetSoftwareMesh(content)); }
public Software.Mesh GetSoftwareMesh(ContentPool content) { if (MeshDescription != null) { return(Graphics.Software.Meshes.Construct(MeshDescription)); } else if (MetaMesh != null) { return(content.Peek <Software.Mesh>(MetaMesh)); } else { return(Mesh.Data); } }
public override StructBoxer <BoundingBox> Construct(MeshConcretize metaResource, ContentPool content) { BoundingBox b = new BoundingBox(); if (content.Device9 != null) { var m = content.Peek <SlimDX.Direct3D9.Mesh>(metaResource); if (m != null) { b = Common.Boundings.BoundingBoxFromXMesh(m); } } return(new StructBoxer <BoundingBox> { Value = b }); }
public BoundingBox?GetBoundingBox(Content.ContentPool content) { bool cachedMeshBoundingBoxChanged = false; if (cachedMeshBoundingBox == null || !Object.Equals(cachedMesh, Mesh)) { cachedMesh = (Content.MetaResourceBase)Mesh.Clone(); cachedMeshBoundingBox = content.Peek <Content.StructBoxer <BoundingBox> >(Mesh).Value; cachedBoundingBox = cachedMeshBoundingBox = new BoundingBox( cachedMeshBoundingBox.Value.Minimum - new Vector3(0.1f, 0.1f, 0.1f), cachedMeshBoundingBox.Value.Maximum + new Vector3(0.1f, 0.1f, 0.1f)); cachedMeshBoundingBoxChanged = true; } if (cachedMeshBoundingBoxChanged || Transformation != cachedTransformation) { cachedTransformation = Transformation; cachedBoundingBox = (BoundingBox)Common.Boundings.Transform(cachedMeshBoundingBox, Transformation); } return(cachedBoundingBox); }
public override Software.Mesh Construct(MeshFromFile metaResource, ContentPool content) { var mesh = content.Peek <SlimDX.Direct3D9.Mesh>(metaResource); return(new Graphics.Software.Mesh(mesh)); }
public static BoundingBox BoundingToBox(BoundingMetaMesh bounding) { return(content.Peek <Content.StructBoxer <BoundingBox> >(bounding.Mesh).Value); }