public static Vector3D GenerateRandomBorderPosition(Vector3 borderStart, Vector3 borderEnd)
        {
            BoundingBoxD box    = new BoundingBoxD(borderStart, borderEnd);
            Vector3D     result = MyVRageUtils.GetRandomBorderPosition(ref box);

            return(result);
        }
        //  Get normal from lookup table or calc it
        void GetVoxelNormal(MyTemporaryVoxel temporaryVoxel, ref Vector3I coord, ref Vector3I voxelCoord, MyTemporaryVoxel centerVoxel)
        {
            if (temporaryVoxel.Normal_CalcCounter != m_temporaryVoxelsCounter)
            {
                if ((voxelCoord.X == 0) || (voxelCoord.X == (m_sizeMinusOne.X)) ||
                    (voxelCoord.Y == 0) || (voxelCoord.Y == (m_sizeMinusOne.Y)) ||
                    (voxelCoord.Z == 0) || (voxelCoord.Z == (m_sizeMinusOne.Z)))
                {
                    //  If asked for normal vector for voxel that is at the voxel map border, we can't compute it by gradient, so return this hack.
                    temporaryVoxel.Normal = centerVoxel.Normal;
                }
                else
                {
                    var     cache  = ThreadLocalCache;
                    Vector3 normal = new Vector3(
                        (cache.Content(coord.X - 1, coord.Y, coord.Z) - cache.Content(coord.X + 1, coord.Y, coord.Z)) / MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT,
                        (cache.Content(coord.X, coord.Y - 1, coord.Z) - cache.Content(coord.X, coord.Y + 1, coord.Z)) / MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT,
                        (cache.Content(coord.X, coord.Y, coord.Z - 1) - cache.Content(coord.X, coord.Y, coord.Z + 1)) / MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT);

                    if (normal.LengthSquared() <= 0.0f)
                    {
                        //  If voxels surounding voxel for which we want to get normal vector are of the same value, their subtracting leads to zero vector and that can't be used. So following line is hack.
                        temporaryVoxel.Normal = centerVoxel.Normal;
                    }
                    else
                    {
                        MyVRageUtils.Normalize(ref normal, out temporaryVoxel.Normal);
                    }
                }
                temporaryVoxel.Normal_CalcCounter = m_temporaryVoxelsCounter;
            }
        }
        //  Linearly interpolates position, normal and material on poly-cube edge. Interpolated point is where an isosurface cuts an edge between two vertices, each with their own scalar value.
        void GetVertexInterpolation(MyStorageDataCache cache, MyTemporaryVoxel inputVoxelA, MyTemporaryVoxel inputVoxelB, int edgeIndex)
        {
            MyEdge edge = m_edges[edgeIndex];

            byte contentA  = cache.Content(inputVoxelA.IdxInCache);
            byte contentB  = cache.Content(inputVoxelB.IdxInCache);
            byte materialA = cache.Material(inputVoxelA.IdxInCache);
            byte materialB = cache.Material(inputVoxelB.IdxInCache);

            if (Math.Abs(MyVoxelConstants.VOXEL_ISO_LEVEL - contentA) < 0.00001f)
            {
                edge.Position = inputVoxelA.Position;
                edge.Normal   = inputVoxelA.Normal;
                edge.Material = materialA;
                edge.Ambient  = inputVoxelA.Ambient;
                return;
            }

            if (Math.Abs(MyVoxelConstants.VOXEL_ISO_LEVEL - contentB) < 0.00001f)
            {
                edge.Position = inputVoxelB.Position;
                edge.Normal   = inputVoxelB.Normal;
                edge.Material = materialB;
                edge.Ambient  = inputVoxelB.Ambient;
                return;
            }

            float mu = (float)(MyVoxelConstants.VOXEL_ISO_LEVEL - contentA) / (float)(contentB - contentA);

            Debug.Assert(mu > 0.0f && mu < 1.0f);

            edge.Position.X = inputVoxelA.Position.X + mu * (inputVoxelB.Position.X - inputVoxelA.Position.X);
            edge.Position.Y = inputVoxelA.Position.Y + mu * (inputVoxelB.Position.Y - inputVoxelA.Position.Y);
            edge.Position.Z = inputVoxelA.Position.Z + mu * (inputVoxelB.Position.Z - inputVoxelA.Position.Z);

            edge.Normal.X = inputVoxelA.Normal.X + mu * (inputVoxelB.Normal.X - inputVoxelA.Normal.X);
            edge.Normal.Y = inputVoxelA.Normal.Y + mu * (inputVoxelB.Normal.Y - inputVoxelA.Normal.Y);
            edge.Normal.Z = inputVoxelA.Normal.Z + mu * (inputVoxelB.Normal.Z - inputVoxelA.Normal.Z);
            if (MyVRageUtils.IsZero(edge.Normal))
            {
                edge.Normal = inputVoxelA.Normal;
            }
            else
            {
                edge.Normal = MyVRageUtils.Normalize(edge.Normal);
            }

            float mu2 = ((float)contentB) / (((float)contentA) + ((float)contentB));

            edge.Material = (mu2 <= 0.5f) ? materialA : materialB;
            edge.Ambient  = inputVoxelA.Ambient + mu2 * (inputVoxelB.Ambient - inputVoxelA.Ambient);

            return;
        }
Beispiel #4
0
        public MyInMemoryWave GetRandomWave(MyObjectBuilder_CueDefinition cue)
        {
            int            randomIndex = MyVRageUtils.GetRandomInt(cue.Waves.Length);
            string         waveToPlay  = cue.Waves[randomIndex];
            MyInMemoryWave wave        = m_waveBank.GetWave(waveToPlay);

            if (wave == null)
            {
                return(null);
            }

            return(wave);
        }
Beispiel #5
0
        public string GetRandomTransitionCategory(MyMusicTransitionEnum transitionEnum)
        {
            int randomIndex  = MyVRageUtils.GetRandomInt(m_musicTransitionCues[(int)transitionEnum].Count);
            int currentIndex = 0;

            foreach (var categoryCueKVP in m_musicTransitionCues[(int)transitionEnum])
            {
                if (currentIndex == randomIndex)
                {
                    return(categoryCueKVP.Key);
                }
                currentIndex++;
            }
            throw new InvalidBranchException();
        }
Beispiel #6
0
        private void EnsureMutable()
        {
            if (!IsMutable)
            {
                MyStorageBase existingStorage = null;
                string        newName;
                do
                {
                    newName = string.Format("{0}-{1}", m_trueStorage.Name, MyVRageUtils.GetRandomInt(int.MaxValue).ToString("########"));
                    MySession.Static.VoxelMaps.TryGetStorage(newName, out existingStorage);
                }while(existingStorage != null);

                m_trueStorage = m_trueStorage.DeepCopy(newName);
                IsMutable     = true;
            }
        }
Beispiel #7
0
        public bool WrinkleVoxelContent(ref Vector3I p, float wrinkleWeightAdd, float wrinkleWeightRemove)
        {
            int max = Int32.MinValue, min = Int32.MaxValue;
            int randomizationAdd    = (int)(wrinkleWeightAdd * 255);
            int randomizationRemove = (int)(wrinkleWeightRemove * 255);

            for (int z = -1; z <= 1; z++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    for (int x = -1; x <= 1; x++)
                    {
                        Vector3I tempVoxelCoord = new Vector3I(p.X + x, p.Y + y, p.Z + z);
                        var      content        = Content(ref tempVoxelCoord);
                        max = Math.Max(max, content);
                        min = Math.Min(min, content);
                    }
                }
            }

            if (min == max)
            {
                return(false);
            }

            int old = Content(ref p);

            byte newVal             = (byte)MyVRageUtils.GetClampInt(old + MyVRageUtils.GetRandomInt(randomizationAdd + randomizationRemove) - randomizationRemove, min, max);

            newVal = MyCellStorage.Quantizer.QuantizeValue(newVal);

            if (newVal != old)
            {
                Content(ref p, (byte)newVal);
                return(true);
            }
            return(false);
        }
Beispiel #8
0
 public MyMusicTransitionEnum GetRandomTransitionEnum()
 {
     return((MyMusicTransitionEnum)MyVRageUtils.GetRandomInt(m_musicTransitionCues.Length));
 }
Beispiel #9
0
 private int GetNumberOfSounds()
 {
     return(MyVRageUtils.GetMaxValueFromEnum <MySoundCuesEnum>() + 1);
 }
Beispiel #10
0
 private void InitTransitionCues()
 {
     m_musicTransitionCues = new Dictionary <string, MySoundCuesEnum> [MyVRageUtils.GetMaxValueFromEnum <MyMusicTransitionEnum>() + 1];
 }