// Calculates intersection of line with any triangleVertexes in this model instance. Closest intersection and intersected triangleVertexes will be returned. internal override bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx? t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES) { t = null; return false; //Matrix invWorld = Matrix.Invert(WorldMatrix); //Vector3 from = Vector3.Transform(line.From, invWorld); //Vector3 to = Vector3.Transform(line.To, invWorld); //Line lineLocal = new Line(from, to); //bool res = base.GetIntersectionWithLine(ref line, out t, flags); //if (res) //{ // var definition = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(MyObjectBuilderTypeEnum.Ladder)); // if (definition.ExcludedAreaForCamera != null) // { // foreach (var b in definition.ExcludedAreaForCamera) // { // if (b.Contains(t.Value.IntersectionPointInObjectSpace) == ContainmentType.Contains) // { // t = null; // return false; // } // } // } //} //return res; }
// Method finds intersection with line and any voxel triangleVertexes in this voxel map. Closes intersection is returned. internal override bool GetIntersectionWithLine(ref LineD worldLine, out MyIntersectionResultLineTriangleEx? t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES) { t = null; double intersectionDistance; LineD line = (LineD)worldLine; if (!PositionComp.WorldAABB.Intersects(line, out intersectionDistance)) return false; ProfilerShort.Begin("VoxelMap.LineIntersection"); try { Line localLine = new Line(worldLine.From - PositionLeftBottomCorner, worldLine.To - PositionLeftBottomCorner, true); MyIntersectionResultLineTriangle tmpResult; if (Storage.Geometry.Intersect(ref localLine, out tmpResult, flags)) { t = new MyIntersectionResultLineTriangleEx(tmpResult, this, ref worldLine); var tmp = t.Value.IntersectionPointInWorldSpace; tmp.AssertIsValid(); return true; } else { t = null; return false; } } finally { ProfilerShort.End(); } }
// Calculates intersection of line with any triangleVertexes in this model instance. Closest intersection and intersected triangleVertexes will be returned. internal virtual bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx? t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES) { bool ret = false; t = null; MyModel collisionModel = Model; if (collisionModel != null) { VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyEntity.GetIntersectionWithLine on model"); MyIntersectionResultLineTriangleEx? result = collisionModel.GetTrianglePruningStructure().GetIntersectionWithLine(this, ref line, flags); VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock(); if (result != null) { t = result.Value; ret = true; } } return ret; }
public bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx? t, out ushort blockId, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES, bool checkZFight = false, bool ignoreGenerated = false) { t = null; blockId = 0; double distanceSquaredInCompound = double.MaxValue; bool foundIntersection = false; foreach (var blockPair in m_blocks) { MySlimBlock cmpSlimBlock = blockPair.Value; if (ignoreGenerated && cmpSlimBlock.BlockDefinition.IsGeneratedBlock) continue; MyIntersectionResultLineTriangleEx? intersectionTriResult; if (cmpSlimBlock.FatBlock.GetIntersectionWithLine(ref line, out intersectionTriResult) && intersectionTriResult != null) { Vector3D startToIntersection = intersectionTriResult.Value.IntersectionPointInWorldSpace - line.From; double instrDistanceSq = startToIntersection.LengthSquared(); if (instrDistanceSq < distanceSquaredInCompound) { if (checkZFight && distanceSquaredInCompound < instrDistanceSq + 0.001f) continue; distanceSquaredInCompound = instrDistanceSq; t = intersectionTriResult; blockId = blockPair.Key; foundIntersection = true; } } } return foundIntersection; }
// Find if distance between two intersections is less than "tolerance distance". public static bool IsDistanceLessThanTolerance(ref MyIntersectionResultLineTriangleEx? a, ref MyIntersectionResultLineTriangleEx? b, float distanceTolerance) { if (((a == null) && (b != null)) || ((a != null) && (b != null) && (Math.Abs(b.Value.Triangle.Distance - a.Value.Triangle.Distance) <= distanceTolerance))) { return true; } else { // This will be returned also when ((a == null) && (b == null)) return false; } }
// Find and return closer intersection of these two. If intersection is null then it's not really an intersection. public static MyIntersectionResultLineTriangleEx? GetCloserIntersection(ref MyIntersectionResultLineTriangleEx? a, ref MyIntersectionResultLineTriangleEx? b) { if (((a == null) && (b != null)) || ((a != null) && (b != null) && (b.Value.Triangle.Distance < a.Value.Triangle.Distance))) { // If only "b" contains valid intersection, or when it's closer than "a" return b; } else { // This will be returned also when ((a == null) && (b == null)) return a; } }
// Calculates intersection of line with any triangleVertexes in this model instance. Closest intersection and intersected triangleVertexes will be returned. internal override bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx? t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES) { t = null; return false; }
internal bool Intersect(ref Line worldLine, out MyIntersectionResultLineTriangleEx? result, IntersectionFlags flags) { Line localLine = new Line(worldLine.From - m_voxelMap.PositionLeftBottomCorner, worldLine.To - m_voxelMap.PositionLeftBottomCorner, true); Profiler.Begin("VoxelMap.LineIntersection AABB sweep"); m_sweepResultCache.Clear(); MyGridIntersection.Calculate( m_sweepResultCache, (int)MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_METRES, localLine.From, localLine.To, new Vector3I(0, 0, 0), m_cellsCount - 1 ); Profiler.End(); Profiler.Begin("VoxelMap.LineIntersection test AABBs"); float? minDistanceUntilNow = null; BoundingBox cellBoundingBox; Vector3I cellCoord; MyIntersectionResultLineTriangle? tmpResult = null; for (int index = 0; index < m_sweepResultCache.Count; index++) { var coord = m_sweepResultCache[index]; cellCoord = coord; GetDataCellBoundingBox(ref cellCoord, out cellBoundingBox); float? distanceToBoundingBox = MyUtils.GetLineBoundingBoxIntersection(ref worldLine, ref cellBoundingBox); // Sweep results are sorted; when we get far enough, make an early exit const float earlyOutDistance = 1.948557f * MyVoxelConstants.GEOMETRY_CELL_SIZE_IN_METRES; // = sqrt(3) * 9/8 * cell_side if (minDistanceUntilNow != null && distanceToBoundingBox != null && minDistanceUntilNow + earlyOutDistance < distanceToBoundingBox.Value) { break; } // Get cell from cache. If not there, precalc it and store in the cache. // If null is returned, we know that cell doesn't contain any triangleVertexes so we don't need to do intersections. CellData cachedDataCell = GetCell(MyLodTypeEnum.LOD0, ref cellCoord); if (cachedDataCell == null || cachedDataCell.VoxelTrianglesCount == 0) continue; GetCellLineIntersectionOctree(ref tmpResult, ref localLine, ref minDistanceUntilNow, cachedDataCell, flags); } Profiler.End(); if (tmpResult.HasValue) { result = new MyIntersectionResultLineTriangleEx(tmpResult.Value, m_voxelMap, ref worldLine); return true; } else { result = null; return false; } }
// Method finds intersection with line and any voxel triangleVertexes in this voxel map. Closes intersection is returned. internal override bool GetIntersectionWithLine(ref Line worldLine, out MyIntersectionResultLineTriangleEx? t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES) { t = null; float intersectionDistance; if (!m_worldAABB.Intersects(worldLine, out intersectionDistance)) return false; Profiler.Begin("VoxelMap.LineIntersection"); try { return Geometry.Intersect(ref worldLine, out t, flags); } finally { Profiler.End(); } }