Exemplo n.º 1
0
        unsafe static public bool setMaskAlphaToLayer(BTerrainQuadNode node, UInt32 *mskImg, uint mskImgWidth, uint mskImgHeight, float alphaScalar,
                                                      int terrainGridX, int terrainGridZ, char index)
        {
            bool  changed            = false;
            uint  dstImgWidth        = BTerrainTexturing.getAlphaTextureWidth();
            uint  dstImgHeight       = BTerrainTexturing.getAlphaTextureWidth();
            float vertsToPixelsRatio = BTerrainTexturing.getAlphaTextureWidth() / (float)BTerrainQuadNode.getMaxNodeWidth();


            int minxvert = node.getDesc().mMinXVert;
            int minzvert = node.getDesc().mMinZVert;
            int maxxvert = node.getDesc().mMaxXVert;
            int maxzvert = node.getDesc().mMaxZVert;

            BTerrainLayerContainer layers = node.mLayerContainer;
            int layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat);

            if (TerrainGlobals.getEditor().mEraseTextureInstead&& layerIndex == 0)
            {
                return(false);
            }

            //  layers.removeRedundantLayers();//CLM is this still needed?!??!

            if (layerIndex == -1)
            {
                if (TerrainGlobals.getEditor().mEraseTextureInstead) //we're erasing, and the texture doesn't exist..
                {
                    return(false);
                }

                //i don't exist yet.
                newSplatLayerEverywhere(index);
                layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat);
                BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex);

                for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++)
                {
                    for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++)
                    {
                        float curWeight = TerrainGlobals.getTerrain().getSoftSelectionWeight(terrainGridX, terrainGridZ);
                        if (!BMathLib.compare(curWeight, 0.0f))
                        {
                            int cX = (int)((x * vertsToPixelsRatio) + minxvert);
                            int cZ = (int)((z * vertsToPixelsRatio) + minzvert);

                            curWeight = BMathLib.Clamp(curWeight, 0, 1);


                            int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z;

                            byte alphaMapVal = giveBrushAlphaValue(mskImg, mskImgWidth, mskImgHeight, minxvert, minzvert, maxxvert, maxzvert, cX, cZ, terrainGridX, terrainGridZ);

                            byte val = (byte)(alphaMapVal * alphaScalar * curWeight);
                            tLayer.mAlphaLayer[dIP] = val;
                        }
                    }
                }
                changed = true;
            }
            else
            {
                BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex);
                //this layer already exists.
                //If a pixel exists above me, subtract me from it, rather than adding to me.
                for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++)
                {
                    for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++)
                    {
                        //find the closest vert
                        int cX = (int)((x * vertsToPixelsRatio) + minxvert);
                        int cZ = (int)((z * vertsToPixelsRatio) + minzvert);

                        int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z;

                        float curWeight = TerrainGlobals.getTerrain().getSoftSelectionWeight(terrainGridX, terrainGridZ);
                        if (!BMathLib.compare(curWeight, 0.0f))
                        {
                            changed   = true;
                            curWeight = BMathLib.Clamp(curWeight, 0, 1);


                            byte alphaMapVal = giveBrushAlphaValue(mskImg, mskImgWidth, mskImgHeight, minxvert, minzvert, maxxvert, maxzvert, cX, cZ, terrainGridX, terrainGridZ);

                            byte val = (byte)(alphaMapVal * alphaScalar * curWeight);

                            valToLayerColumn(layers, tLayer, dIP, val, layerIndex);
                        }
                    }
                }
            }

            layers.removeBlankLayers();

            return(changed);
        }
Exemplo n.º 2
0
        //----------------------------------------------
        unsafe static public bool setIndexToMaskedArea(BTerrainQuadNode node, int minxvert, int minzvert, int maxxvert, int maxzvert, char index)
        {
            bool  changed            = false;
            uint  dstImgWidth        = BTerrainTexturing.getAlphaTextureWidth();
            uint  dstImgHeight       = BTerrainTexturing.getAlphaTextureWidth();
            float vertsToPixelsRatio = BTerrainTexturing.getAlphaTextureWidth() / (float)BTerrainQuadNode.getMaxNodeWidth();

            BTerrainLayerContainer layers = node.mLayerContainer;
            int layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat);

            if (TerrainGlobals.getEditor().mEraseTextureInstead&& layerIndex == 0)
            {
                return(false);
            }

            //layers.removeRedundantLayers();//CLM is this still needed?!??!

            if (layerIndex == -1)
            {
                if (TerrainGlobals.getEditor().mEraseTextureInstead) //we're erasing, and the texture doesn't exist..
                {
                    return(false);
                }

                //i don't exist yet.
                newSplatLayerEverywhere(index);
                layerIndex = layers.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat);
                BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex);

                for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++)
                {
                    for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++)
                    {
                        //find the closest vert
                        int cX = (int)((x * vertsToPixelsRatio) + minxvert);
                        int cZ = (int)((z * vertsToPixelsRatio) + minzvert);

                        int vertIndex = (int)(cX * TerrainGlobals.getTerrain().getNumZVerts() + cZ);

                        float curWeight = 1.0f;
                        if (Masking.isPointSelected(vertIndex, ref curWeight))
                        {
                            curWeight = BMathLib.Clamp(curWeight, 0, 1);


                            int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z;

                            byte val = (byte)(curWeight * byte.MaxValue);
                            tLayer.mAlphaLayer[dIP] = val;
                        }
                    }
                }
                changed = true;
            }
            else
            {
                BTerrainTexturingLayer tLayer = layers.giveLayer(layerIndex);
                //this layer already exists.
                //If a pixel exists above me, subtract me from it, rather than adding to me.
                for (int x = 0; x < BTerrainTexturing.getAlphaTextureWidth(); x++)
                {
                    for (int z = 0; z < BTerrainTexturing.getAlphaTextureWidth(); z++)
                    {
                        //find the closest vert
                        int cX = (int)((x * vertsToPixelsRatio) + minxvert);
                        int cZ = (int)((z * vertsToPixelsRatio) + minzvert);

                        int vertIndex = (int)(cX * TerrainGlobals.getTerrain().getNumZVerts() + cZ);

                        float curWeight = 1.0f;
                        if (Masking.isPointSelected(vertIndex, ref curWeight))
                        {
                            changed = true;
                            int dIP = x + ((int)BTerrainTexturing.getAlphaTextureHeight()) * z;
                            curWeight = BMathLib.Clamp(curWeight, 0, 1);


                            byte val = (byte)(curWeight * byte.MaxValue);

                            valToLayerColumn(layers, tLayer, dIP, val, layerIndex);
                        }
                    }
                }
            }

            layers.removeBlankLayers();

            return(changed);
        }