コード例 #1
0
            public override void Draw()
            {
                base.Draw();

                if (MySession.Static == null)
                {
                    return;
                }

                if (m_showVoxelProbe)
                {
                    float halfSize = m_probeSize * .5f;
                    float lodSize  = 1 << m_probeLod;

                    if (m_moveProbe)
                    {
                        m_probePosition = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * m_probeSize * 3;
                    }

                    BoundingBox  bb;
                    BoundingBoxD bbp; // Box used for drawing and finding the probe and drawing

                    bb  = new BoundingBox(m_probePosition - halfSize, m_probePosition + halfSize);
                    bbp = (BoundingBoxD)bb;

                    m_voxels.Clear();
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbp, m_voxels);

                    MyVoxelBase map      = null;
                    double      distance = double.PositiveInfinity;

                    foreach (var vox in m_voxels)
                    {
                        var d = Vector3D.Distance(vox.WorldMatrix.Translation, m_probePosition);
                        if (d < distance)
                        {
                            distance = d;
                            map      = vox;
                        }
                    }

                    ContainmentType cont = ContainmentType.Disjoint;

                    if (map != null)
                    {
                        map = map.RootVoxel;

                        Vector3 localPos = Vector3.Transform(m_probePosition, map.PositionComp.WorldMatrixInvScaled);
                        localPos += map.SizeInMetresHalf;

                        // Create similar bounding box in storage space
                        bb = new BoundingBox(localPos - halfSize, localPos + halfSize);

                        m_probedVoxel = map;

                        Section("Probing {1}: {0}", map.StorageName, map.GetType().Name);
                        Text("Probe mode: {0}", m_mode);

                        if (m_mode == ProbeMode.Intersect)
                        {
                            Text("Local Pos: {0}", localPos);
                            Text("Probe Size: {0}", m_probeSize);
                            cont = map.Storage.Intersect(ref bb, false);
                            Text("Result: {0}", cont.ToString());
                            bbp = (BoundingBoxD)bb;
                        }
                        else
                        {
                            Vector3I min = Vector3I.Floor(bb.Min / lodSize + .5f);
                            Vector3I max = min + ((int)m_probeSize >> m_probeLod) - 1;

                            bbp = new BoundingBoxD(min << m_probeLod, (max + 1) << m_probeLod);
                            bbp.Translate(new Vector3D(-.5));

                            Text("Probe Size: {0}({1})", (max - min).X + 1, m_probeSize);
                            Text("Probe LOD: {0}", m_probeLod);

                            var requestData           = (MyStorageDataTypeEnum)(int)m_mode;
                            MyVoxelRequestFlags flags = MyVoxelRequestFlags.ContentChecked;

                            m_target.Resize(max - min + 1);
                            m_target.Clear(MyStorageDataTypeEnum.Content, 0);
                            m_target.Clear(MyStorageDataTypeEnum.Material, 0);
                            map.Storage.ReadRange(m_target, (MyStorageDataTypeFlags)(1 << (int)requestData), m_probeLod, ref min, ref max, ref flags);

                            if (requestData == MyStorageDataTypeEnum.Content)
                            {
                                if (flags.HasFlag(MyVoxelRequestFlags.EmptyContent))
                                {
                                    cont = ContainmentType.Disjoint;
                                }
                                else if (flags.HasFlag(MyVoxelRequestFlags.FullContent))
                                {
                                    cont = ContainmentType.Contains;
                                }
                                else
                                {
                                    int val = m_target.ValueWhenAllEqual(requestData);
                                    if (val == -1)
                                    {
                                        cont = ContainmentType.Intersects;
                                    }
                                    else if (val >= MyVoxelConstants.VOXEL_ISO_LEVEL)
                                    {
                                        cont = ContainmentType.Contains;
                                    }
                                    else
                                    {
                                        cont = ContainmentType.Disjoint;
                                    }
                                }

                                DrawContentsInfo(m_target);
                            }
                            else
                            {
                                cont = ContainmentType.Disjoint;
                                DrawMaterialsInfo(m_target);
                            }

                            Text(Color.Yellow, 1.5f, "Voxel Editing:");
                            Text("Value to set (Ctrl+Mousewheel): {0}", m_valueToSet);
                            if (m_probeLod != 0)
                            {
                                Text(Color.Red, "Writing to storage is only possible when probe is set to LOD 0");
                            }
                            else
                            {
                                Text("Use primary mouse button to set.");
                                Text("Position/Extents: {0}/{1}", bbp.Min, bbp.Extents);

                                if (MyInput.Static.IsLeftMousePressed())
                                {
                                    if (requestData == MyStorageDataTypeEnum.Content)
                                    {
                                        m_target.BlockFillContent(Vector3I.Zero, m_target.Size3D - Vector3I.One, m_valueToSet);
                                    }
                                    else
                                    {
                                        m_target.BlockFillMaterial(Vector3I.Zero, m_target.Size3D - Vector3I.One, m_valueToSet);
                                    }

                                    map.Storage.WriteRange(m_target, (MyStorageDataTypeFlags)(1 << (int)requestData), ref min, ref max);
                                }
                            }
                        }
                    }
                    else
                    {
                        Section("No Voxel Found");
                        Text("Probe mode: {0}", m_mode);
                        Text("Probe Size: {0}", m_probeSize);
                    }

                    Color c = ColorForContainment(cont);
                    if (map != null)
                    {
                        bbp = bbp.Translate(-map.SizeInMetresHalf);
                        MyOrientedBoundingBoxD oobb = new MyOrientedBoundingBoxD(bbp, map.WorldMatrix);
                        MyRenderProxy.DebugDrawOBB(oobb, c, 0.5f, true, false);
                    }
                    else
                    {
                        MyRenderProxy.DebugDrawAABB(bbp, c, 0.5f, 1.0f, true);
                    }
                }
            }
コード例 #2
0
        private bool CalculateSafePositionAndSpawn(bool keepOriginalLocation, Vector3D Target)
        {
            //This has to be ran on the main game thread!
            if (keepOriginalLocation)
            {
                var BoundingBox = FindBoundingBox(_grids);



                //sphere.Center = Target;
                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllEntitiesInOBB(ref BoundingBox, entities);


                Hangar.Debug(BoundingBox.ToString());

                Hangar.Debug(entities.Count.ToString());
                bool PotentialGrids = false;
                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        PotentialGrids = true;

                        BoundingBox     Box  = entity.PositionComp.LocalAABB;
                        ContainmentType Type = BoundingBox.Contains(ref Box);

                        Hangar.Debug(entity.DisplayName + " is intersecting spawn area! Containment Type: " + Type.ToString());


                        _Response.Respond("There are potentially other grids in the way. Attempting to spawn around the location to avoid collisions.");
                        break;
                    }
                }


                if (PotentialGrids)
                {
                    var pos = FindPastePosition(Target);
                    if (!pos.HasValue)
                    {
                        _Response.Respond("No free spawning zone found! Stopping load!");
                        return(false);
                    }

                    UpdateGridsPosition(pos.Value);
                    return(true);
                }
                else
                {
                    return(true);
                }
            }


            //Everything else is loading for near point
            if (!keepOriginalLocation)
            {
                /* Where do we want to paste the grids? Lets find out. */
                var pos = FindPastePosition(Target);
                if (pos == null)
                {
                    _Response.Respond("No free spawning zone found! Stopping load!");
                    return(false);
                }

                var newPosition = pos.Value;

                /* Update GridsPosition if that doesnt work get out of here. */
                if (!UpdateGridsPosition(newPosition))
                {
                    _Response.Respond("The File to be imported does not seem to be compatible with the server!");
                    return(false);
                }
            }
            return(true);
        }