예제 #1
0
        public static Image ExportMask(IMask mask)
        {
            int       width  = TerrainGlobals.getTerrain().getNumXVerts();
            int       height = TerrainGlobals.getTerrain().getNumZVerts();
            Rectangle r      = new Rectangle(0, 0, width, height);

            Bitmap destination = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            unsafe
            {
                BitmapData outputData = destination.LockBits(r, ImageLockMode.WriteOnly, destination.PixelFormat);
                if (outputData.PixelFormat == PixelFormat.Format24bppRgb)
                {
                    PixelData24 *outputBase = (PixelData24 *)outputData.Scan0;

                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            PixelData24 *pPixel      = outputBase + y * width + x;
                            long         index       = y * width + x;
                            float        value       = mask.GetMaskWeight(index);
                            byte         outputValue = (byte)(value * byte.MaxValue);
                            pPixel->blue  = outputValue;
                            pPixel->red   = outputValue;
                            pPixel->green = outputValue;
                        }
                    }
                    destination.UnlockBits(outputData);
                }
            }
            return((Image)destination);
        }
예제 #2
0
        static public void invertSelectionMask()
        {
            mCurrSelectionMaskExtends.empty();
            int imgWidth = TerrainGlobals.getTerrain().getNumXVerts();

            for (int x = 0; x < imgWidth; x++)
            {
                for (int y = 0; y < imgWidth; y++)
                {
                    int   index  = x * imgWidth + y;
                    float weight = mCurrSelectionMask.GetMaskWeight(index);
                    addSelectedVert(x, y, 1 - weight);
                }
            }
            rebuildVisualsAfterSelection();
        }
예제 #3
0
 static public bool checkBaseWritePermission(long id, out float value)
 {
     value = 1.0f;
     if (mBaseMaskingMask != null)
     {
         value = mBaseMaskingMask.GetMaskWeight(id);
         if (value == 0)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #4
0
        private void ToFileButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog d = new SaveFileDialog();

            d.Filter = "Raw32 (*.r32)|*.r32";
            if (d.ShowDialog() == DialogResult.OK)
            {
                BinaryWriter w    = new BinaryWriter(File.OpenWrite(d.FileName));
                IMask        mask = Masking.getCurrSelectionMaskWeights();
                long         max  = TerrainGlobals.getTerrain().getNumXVerts() * TerrainGlobals.getTerrain().getNumXVerts();
                for (long i = 0; i < max; i++)
                {
                    w.Write(mask.GetMaskWeight(i));
                }
                w.Close();
            }
        }
예제 #5
0
        private IMask AddMasks(List <IMask> inputs)
        {
            IMask mask = MaskFactory.GetNewMask();

            foreach (IMask input in inputs)
            {
                if (input is GraphBasedMask)
                {
                    ((GraphBasedMask)input).loadAndExecute();
                }

                float destVal;

                long  index;
                float value;
                input.ResetIterator();
                while (input.MoveNext(out index, out value))
                {
                    float baseValue = 1.0f;
                    if (Masking.checkBaseWritePermission(index, out baseValue) == false)
                    {
                        continue;
                    }

                    if (value == 0)
                    {
                        continue;
                    }
                    destVal = mask.GetMaskWeight(index);
                    //if (destVal == 0) continue;
                    destVal = value + destVal;
                    if (destVal > 1)
                    {
                        destVal = 1;
                    }

                    destVal = Masking.combineValueWithBaseMask(baseValue, destVal);
                    mask.SetMaskWeight(index, destVal);
                }
            }
            return(mask);
        }
예제 #6
0
        public static void MaskCurrentTexture(bool bUseTextureFade)
        {
            int totalNumVerts = TerrainGlobals.getTerrain().getNumXVerts();
            int i             = -1;

            int selTexIndex = TerrainGlobals.getTerrainFrontEnd().SelectedTextureIndex;

            BTerrainActiveTextureContainer activeTex = TerrainGlobals.getTexturing().getActiveTexture(TerrainGlobals.getTerrainFrontEnd().SelectedTextureIndex);

            if (activeTex.mMatHasMask == false)
            {
                return;
            }

            Image img = Image.FromFile(activeTex.getMaskFileName());

            if (img == null)
            {
                return;
            }
            IMask m = CreateMask(img);

            if (m == null)
            {
                return;
            }
            img.Dispose();

            for (int x = 0; x < totalNumVerts; x++)
            {
                for (int z = 0; z < totalNumVerts; z++)
                {
                    float baseValue;
                    float factor = 0;
                    if (checkBaseWritePermission(x, z, out baseValue) == false)
                    {
                        continue;
                    }
                    BTerrainTextureVector vec = TerrainGlobals.getEditor().giveTextureDataAtVertex(x, z);

                    if (vec.containsID(selTexIndex, BTerrainTexturingLayer.eLayerType.cLayer_Splat))
                    {
                        int splatindex = vec.giveLayerIndex(selTexIndex, BTerrainTexturingLayer.eLayerType.cLayer_Splat);

                        float layeralpha = vec.mLayers[splatindex].mAlphaContrib / 255f;
                        float maskAlpha  = 0;
                        if (layeralpha == 0)
                        {
                            continue;
                        }


                        maskAlpha = m.GetMaskWeight(((z % 64) * 64) + (x % 64));
                        //layeralpha = m.GetMaskWeight((( x) * totalNumVerts) + ( z));
                        if (bUseTextureFade)
                        {
                            maskAlpha = maskAlpha * layeralpha;
                        }
                        if (maskAlpha == 0)
                        {
                            continue;
                        }

                        i++;

                        addSelectedVert(x, z, maskAlpha);
                    }
                }
            }
        }