Example #1
0
 public override unsafe void DebugDraw()
 {
     base.DebugDraw();
     if (((this.m_aabbPhantom != null) && MyDebugDrawSettings.DEBUG_DRAW_VOXEL_MAP_AABB) && this.IsInWorld)
     {
         BoundingBoxD aabb = this.m_aabbPhantom.Aabb;
         aabb.Translate(this.ClusterToWorld(Vector3.Zero));
         MyRenderProxy.DebugDrawAABB(aabb, Color.Orange, 1f, 1f, true, false, false);
     }
     if (MyDebugDrawSettings.DEBUG_DRAW_VOXEL_PHYSICS_PREDICTION)
     {
         foreach (IMyEntity entity in this.m_nearbyEntities)
         {
             if (!entity.MarkedForClose)
             {
                 BoundingBoxD xd3;
                 BoundingBoxD worldAABB = entity.WorldAABB;
                 MyRenderProxy.DebugDrawAABB(worldAABB, Color.Bisque, 1f, 1f, true, false, false);
                 MyRenderProxy.DebugDrawLine3D(this.GetWorldMatrix().Translation, worldAABB.Center, Color.Bisque, Color.BlanchedAlmond, true, false);
                 this.GetPrediction(entity, out xd3);
                 MyRenderProxy.DebugDrawAABB(xd3, Color.Crimson, 1f, 1f, true, false, false);
             }
         }
         using (IMyDebugDrawBatchAabb aabb = MyRenderProxy.DebugDrawBatchAABB(this.GetWorldMatrix(), new Color(Color.Cyan, 0.2f), true, false))
         {
             int num = 0;
             foreach (KeyValuePair <MyCellCoord, MyPrecalcJobPhysicsPrefetch> pair in this.m_workTracker)
             {
                 BoundingBoxD xd5;
                 num++;
                 MyCellCoord key = pair.Key;
                 xd5.Min = (Vector3D)(key.CoordInLod << key.Lod);
                 Vector3D *vectordPtr1 = (Vector3D *)ref xd5.Min;
                 vectordPtr1[0] *= 8.0;
                 Vector3D *vectordPtr2 = (Vector3D *)ref xd5.Min;
                 vectordPtr2[0] -= this.m_voxelMap.SizeInMetresHalf;
                 BoundingBoxD *xdPtr1 = (BoundingBoxD *)ref xd5;
                 xdPtr1->Max = xd5.Min + 8f;
                 Color?color = null;
                 aabb.Add(ref xd5, color);
                 if (num > 250)
                 {
                     break;
                 }
             }
         }
     }
 }
Example #2
0
 public override unsafe void DebugDraw(ref Matrix drawMatrix)
 {
     if (MyFakes.DEBUG_DRAW_NAVMESH_PROCESSED_VOXEL_CELLS)
     {
         Vector3 vector  = Vector3.TransformNormal(this.m_cellSize, (Matrix)drawMatrix);
         Vector3 vector2 = Vector3.Transform((Vector3)(this.m_voxelMap.PositionLeftBottomCorner - this.m_voxelMap.PositionComp.GetPosition()), (Matrix)drawMatrix);
         foreach (Vector3I vectori in this.m_processedCells)
         {
             BoundingBoxD xd;
             xd.Min = vector2 + (vector * (new Vector3(0.0625f) + vectori));
             BoundingBoxD *xdPtr1 = (BoundingBoxD *)ref xd;
             xdPtr1->Max = xd.Min + vector;
             xd.Inflate((double)-0.20000000298023224);
             MyRenderProxy.DebugDrawAABB(xd, Color.Orange, 1f, 1f, false, false, false);
             MyRenderProxy.DebugDrawText3D(xd.Center, vectori.ToString(), Color.Orange, 0.5f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false);
         }
     }
     if (MyFakes.DEBUG_DRAW_NAVMESH_CELLS_ON_PATHS)
     {
         Vector3     vector3 = Vector3.TransformNormal(this.m_cellSize, (Matrix)drawMatrix);
         Vector3     vector4 = Vector3.Transform((Vector3)(this.m_voxelMap.PositionLeftBottomCorner - this.m_voxelMap.PositionComp.GetPosition()), (Matrix)drawMatrix);
         MyCellCoord coord   = new MyCellCoord();
         foreach (ulong num in this.m_cellsOnWayCoords)
         {
             BoundingBoxD xd2;
             coord.SetUnpack(num);
             Vector3I coordInLod = coord.CoordInLod;
             xd2.Min = vector4 + (vector3 * (new Vector3(0.0625f) + coordInLod));
             BoundingBoxD *xdPtr2 = (BoundingBoxD *)ref xd2;
             xdPtr2->Max = xd2.Min + vector3;
             xd2.Inflate((double)-0.30000001192092896);
             MyRenderProxy.DebugDrawAABB(xd2, Color.Green, 1f, 1f, false, false, false);
         }
     }
     if (MyFakes.DEBUG_DRAW_NAVMESH_PREPARED_VOXEL_CELLS)
     {
         Vector3  vector5          = Vector3.TransformNormal(this.m_cellSize, (Matrix)drawMatrix);
         Vector3  vector6          = Vector3.Transform((Vector3)(this.m_voxelMap.PositionLeftBottomCorner - this.m_voxelMap.PositionComp.GetPosition()), (Matrix)drawMatrix);
         float    negativeInfinity = float.NegativeInfinity;
         Vector3I zero             = Vector3I.Zero;
         int      index            = 0;
         while (true)
         {
             if (index >= this.m_toAdd.Count)
             {
                 for (int i = 0; i < this.m_toAdd.Count; i++)
                 {
                     BoundingBoxD      xd3;
                     CellToAddHeapItem local1   = this.m_toAdd.GetItem(i);
                     float             num6     = local1.HeapKey;
                     Vector3I          position = local1.Position;
                     xd3.Min = vector6 + (vector5 * (new Vector3(0.0625f) + position));
                     BoundingBoxD *xdPtr3 = (BoundingBoxD *)ref xd3;
                     xdPtr3->Max = xd3.Min + vector5;
                     xd3.Inflate((double)-0.10000000149011612);
                     Color aqua = Color.Aqua;
                     if (position.Equals(zero))
                     {
                         aqua = Color.Red;
                     }
                     MyRenderProxy.DebugDrawAABB(xd3, aqua, 1f, 1f, false, false, false);
                     string text = $"{num6.ToString("n2")}";
                     MyRenderProxy.DebugDrawText3D(xd3.Center, text, aqua, 0.7f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false);
                 }
                 break;
             }
             CellToAddHeapItem item    = this.m_toAdd.GetItem(index);
             float             heapKey = item.HeapKey;
             if (heapKey > negativeInfinity)
             {
                 negativeInfinity = heapKey;
                 zero             = item.Position;
             }
             index++;
         }
     }
     MyRenderProxy.DebugDrawSphere(this.m_debugPos1, 0.2f, Color.Red, 1f, false, false, true, false);
     MyRenderProxy.DebugDrawSphere(this.m_debugPos2, 0.2f, Color.Green, 1f, false, false, true, false);
     MyRenderProxy.DebugDrawSphere(this.m_debugPos3, 0.1f, Color.Red, 1f, false, false, true, false);
     MyRenderProxy.DebugDrawSphere(this.m_debugPos4, 0.1f, Color.Green, 1f, false, false, true, false);
     if (MyFakes.DEBUG_DRAW_VOXEL_CONNECTION_HELPER)
     {
         this.m_connectionHelper.DebugDraw(ref drawMatrix, base.Mesh);
     }
     if (MyFakes.DEBUG_DRAW_NAVMESH_CELL_BORDERS)
     {
         foreach (KeyValuePair <ulong, List <DebugDrawEdge> > pair in this.m_debugCellEdges)
         {
             foreach (DebugDrawEdge edge in pair.Value)
             {
                 MyRenderProxy.DebugDrawLine3D(edge.V1, edge.V2, Color.Orange, Color.Orange, false, false);
             }
         }
     }
     else
     {
         this.m_debugCellEdges.Clear();
     }
     if (MyFakes.DEBUG_DRAW_NAVMESH_HIERARCHY)
     {
         if (MyFakes.DEBUG_DRAW_NAVMESH_HIERARCHY_LITE)
         {
             this.m_higherLevel.DebugDraw(true);
         }
         else
         {
             this.m_higherLevel.DebugDraw(false);
             this.m_higherLevelHelper.DebugDraw();
         }
     }
     if ((MyDebugDrawSettings.DEBUG_DRAW_NAVMESHES == MyWEMDebugDrawMode.LINES) && !(this.m_voxelMap is MyVoxelPhysics))
     {
         int num7 = 0;
         MyWingedEdgeMesh.EdgeEnumerator edges = base.Mesh.GetEdges(null);
         Vector3D position = this.m_voxelMap.PositionComp.GetPosition();
         while (edges.MoveNext())
         {
             MyWingedEdgeMesh.Edge current = edges.Current;
             Vector3D vectord2             = base.Mesh.GetVertexPosition(current.Vertex2) + position;
             Vector3D point = ((base.Mesh.GetVertexPosition(edges.Current.Vertex1) + position) + vectord2) * 0.5;
             if (MyCestmirPathfindingShorts.Pathfinding.Obstacles.IsInObstacle(point))
             {
                 MyRenderProxy.DebugDrawSphere(point, 0.05f, Color.Red, 1f, false, false, true, false);
             }
             num7++;
         }
     }
 }
Example #3
0
        private unsafe void AddVoxelMesh(MyVoxelBase voxelBase, IMyStorage storage, Dictionary <Vector3I, MyIsoMesh> cache, float border, Vector3D originPosition, MyOrientedBoundingBoxD obb, List <BoundingBoxD> bbList)
        {
            Vector3I vectori3;
            Vector3I vectori4;
            bool     flag = cache != null;

            if (flag)
            {
                this.CheckCacheValidity();
            }
            Vector3D *vectordPtr1 = (Vector3D *)ref obb.HalfExtent;

            vectordPtr1[0] += new Vector3D((double)border, 0.0, (double)border);
            BoundingBoxD  aABB   = obb.GetAABB();
            int           num    = (int)Math.Round((double)(aABB.HalfExtents.Max() * 2.0));
            BoundingBoxD *xdPtr1 = (BoundingBoxD *)ref aABB;

            xdPtr1 = (BoundingBoxD *)new BoundingBoxD(aABB.Min, aABB.Min + num);
            ((BoundingBoxD *)ref aABB).Translate(obb.Center - aABB.Center);
            bbList.Add(new BoundingBoxD(aABB.Min, aABB.Max));
            aABB = aABB.TransformFast(voxelBase.PositionComp.WorldMatrixInvScaled);
            aABB.Translate(voxelBase.SizeInMetresHalf);
            Vector3I voxelCoord = Vector3I.Round(aABB.Min);
            Vector3I vectori2   = (Vector3I)(voxelCoord + num);

            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref voxelCoord, out vectori3);
            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref vectori2, out vectori4);
            MyOrientedBoundingBoxD xd2 = obb;

            xd2.Transform(voxelBase.PositionComp.WorldMatrixInvScaled);
            Vector3D *vectordPtr2 = (Vector3D *)ref xd2.Center;

            vectordPtr2[0] += voxelBase.SizeInMetresHalf;
            Vector3I_RangeIterator iterator = new Vector3I_RangeIterator(ref vectori3, ref vectori4);
            MyCellCoord            coord    = new MyCellCoord {
                Lod = 0
            };
            int     num2        = 0;
            Vector3 offset      = (Vector3)(originPosition - voxelBase.PositionLeftBottomCorner);
            Vector3 up          = -Vector3.Normalize(MyGravityProviderSystem.CalculateTotalGravityInPoint(originPosition));
            Matrix  rotation    = Matrix.CreateFromQuaternion(Quaternion.Inverse(Quaternion.CreateFromForwardUp(Vector3.CalculatePerpendicularVector(up), up)));
            Matrix  orientation = (Matrix)voxelBase.PositionComp.WorldMatrix.GetOrientation();

            while (iterator.IsValid())
            {
                BoundingBox box;
                MyIsoMesh   mesh;
                if (flag && cache.TryGetValue(iterator.Current, out mesh))
                {
                    if (mesh != null)
                    {
                        this.AddMeshTriangles(mesh, offset, rotation, orientation);
                    }
                    iterator.MoveNext();
                    continue;
                }
                coord.CoordInLod = iterator.Current;
                MyVoxelCoordSystems.GeometryCellCoordToLocalAABB(ref coord.CoordInLod, out box);
                if (!xd2.Intersects(ref box))
                {
                    num2++;
                    iterator.MoveNext();
                }
                else
                {
                    BoundingBoxD item = new BoundingBoxD(box.Min, box.Max).Translate(-voxelBase.SizeInMetresHalf);
                    bbList.Add(item);
                    Vector3I  lodVoxelMin = (coord.CoordInLod * 8) - 1;
                    MyIsoMesh mesh2       = MyPrecalcComponent.IsoMesher.Precalc(storage, 0, lodVoxelMin, (Vector3I)(((lodVoxelMin + 8) + 1) + 1), MyStorageDataTypeFlags.Content, 0);
                    if (flag)
                    {
                        cache[iterator.Current] = mesh2;
                    }
                    if (mesh2 != null)
                    {
                        this.AddMeshTriangles(mesh2, offset, rotation, orientation);
                    }
                    iterator.MoveNext();
                }
            }
        }
Example #4
0
        internal unsafe void DebugDraw(IMyDebugDrawBatchAabb batch, Vector3 worldPos, MyVoxelDebugDrawMode mode)
        {
            Color?nullable;

            if (mode == MyVoxelDebugDrawMode.Content_MicroNodes)
            {
                foreach (KeyValuePair <uint, MyOctreeNode> pair in this.m_nodes)
                {
                    MyCellCoord coord = new MyCellCoord();
                    coord.SetUnpack(pair.Key);
                    MyOctreeNode node = pair.Value;
                    for (int i = 0; i < 8; i++)
                    {
                        if (!node.HasChild(i) || (coord.Lod == 0))
                        {
                            Vector3I     vectori;
                            BoundingBoxD xd;
                            this.ComputeChildCoord(i, out vectori);
                            Vector3I vectori2 = (Vector3I)((coord.CoordInLod << (coord.Lod + 1)) + (vectori << coord.Lod));
                            xd.Min = worldPos + (vectori2 * 1f);
                            BoundingBoxD *xdPtr1 = (BoundingBoxD *)ref xd;
                            xdPtr1->Max = xd.Min + (1f * (1 << (coord.Lod & 0x1f)));
                            if (node.GetData(i) != 0)
                            {
                                nullable = null;
                                batch.Add(ref xd, nullable);
                            }
                        }
                    }
                }
                return;
            }
            else if (mode != MyVoxelDebugDrawMode.Content_MicroNodesScaled)
            {
                return;
            }
            foreach (KeyValuePair <uint, MyOctreeNode> pair2 in this.m_nodes)
            {
                MyCellCoord coord2 = new MyCellCoord();
                coord2.SetUnpack(pair2.Key);
                MyOctreeNode node2 = pair2.Value;
                for (int i = 0; i < 8; i++)
                {
                    if (!node2.HasChild(i))
                    {
                        Vector3I vectori3;
                        this.ComputeChildCoord(i, out vectori3);
                        float num3 = ((float)node2.GetData(i)) / 255f;
                        if (num3 != 0f)
                        {
                            BoundingBoxD xd2;
                            num3 = (float)Math.Pow(num3 * 1.0, 0.3333);
                            Vector3I vectori4 = (Vector3I)((coord2.CoordInLod << (coord2.Lod + 1)) + (vectori3 << coord2.Lod));
                            float    num4     = 1f * (1 << (coord2.Lod & 0x1f));
                            Vector3  vector   = (worldPos + (vectori4 * 1f)) + (0.5f * num4);
                            xd2.Min  = vector - ((0.5f * num3) * num4);
                            xd2.Max  = vector + ((0.5f * num3) * num4);
                            nullable = null;
                            batch.Add(ref xd2, nullable);
                        }
                    }
                }
            }
        }