public AlphaSplatTerrainConfig(string title, AutoSplatRules autoSplatRules, MosaicDescription srcdesc)
        {
            InitTextureNames();
            // Override texture names from rules, if applicable
            for (int i = 0; i < autoSplatRules.layerTextureNames.Length; i++)
            {
                if (!string.IsNullOrEmpty(autoSplatRules.layerTextureNames[i]))
                {
                    layerTextureNames[i] = autoSplatRules.layerTextureNames[i];
                }
            }

            // Create alpha map texture mosaics
            for (int i = 0; i < NUM_ALPHA_MAPS; i++)
            {
                string            alphaMapMosaicName = title + "AlphaMap" + i;
                MosaicDescription desc = new MosaicDescription(alphaMapMosaicName, srcdesc);

                alphaMapMosaicNames[i] = alphaMapMosaicName;
                alphaMapMosaics[i]     = new TextureMosaic(alphaMapMosaicName, 0, desc);

                alphaMapMosaics[i].MosaicModificationStateChanged += Mosaic_OnMosaicModificationStateChanged;
                alphaMapMosaics[i].MosaicChanged += Mosaic_OnMosaicChanged;
            }

            AutoSplatRules = autoSplatRules;
            InitializeAutoSplatRules(srcdesc);
        }
        /// <summary>
        /// Set the texture map for a point specified by world coordinates.
        /// The 8-byte array is map.  The map can have 8 possible
        /// mappings associated with it with one byte per map.  Ultimately, the
        /// first 4 bytes correspond with Alpha Map 0 and the latter 4 bytes
        /// correspond with Alpha Map 1.
        /// </summary>
        /// <param name="worldXMeters"></param>
        /// <param name="worldZMeters"></param>
        /// <param name="textureMap"></param>
        /// <returns></returns>
        public void SetWorldTextureMap(int worldXMeters, int worldZMeters, byte[] textureMap)
        {
            for (int i = 0; i < alphaMapMosaics.Length; i++)
            {
                byte[] mosaicAlphaMap = new byte[4];
                Array.Copy(textureMap, i * 4, mosaicAlphaMap, 0, 4);

                TextureMosaic alphaMapMosaic = alphaMapMosaics[i];
                alphaMapMosaic.SetWorldTextureMap(worldXMeters, worldZMeters, mosaicAlphaMap);
            }
        }
        /// <summary>
        /// Get the texture map for a point specified by world coordinates
        /// A 8-byte array is returned as the map.  The map can have 8 possible
        /// mappings associated with it with one byte per map.  Ultimately, the
        /// first 4 bytes correspond with Alpha Map 0 and the latter 4 bytes
        /// correspond with Alpha Map 1.
        /// </summary>
        /// <param name="worldXMeters"></param>
        /// <param name="worldZMeters"></param>
        /// <returns></returns>
        public byte[] GetWorldTextureMap(int worldXMeters, int worldZMeters)
        {
            byte[] textureMap = new byte[MAX_LAYER_TEXTURES];

            for (int i = 0; i < alphaMapMosaics.Length; i++)
            {
                TextureMosaic alphaMapMosaic = alphaMapMosaics[i];
                byte[]        mosaicAlphaMap = alphaMapMosaic.GetWorldTextureMap(worldXMeters, worldZMeters);

                Array.Copy(mosaicAlphaMap, 0, textureMap, i * 4, 4);
            }

            return(textureMap);
        }
示例#4
0
        protected void BuildMaterial()
        {
            // If the highlight type changes, we need to use a different shader, so we load a
            // different material to go with it.
            if (typeChange)
            {
                if (material != null)
                {
                    //LogManager.Instance.Write("Free Material: {0}", material.Name);

                    MaterialManager.Instance.Unload(material);
                    material.Dispose();
                    material = null;
                }

                materialName = String.Format("AlphaSplat-{0}-{1}-{2}", pageX, pageZ, HighlightTypeString);

                //LogManager.Instance.Write("Create Material: {0}", materialName);

                Material tmpMaterial = MaterialManager.Instance.GetByName(HighlightMaterialName(highlightType));
                material = tmpMaterial.Clone(materialName);

                typeChange = false;
            }

            Technique tech = material.GetTechnique(0);

            material.Load();
            if (tech.IsSupported)
            {
                Pass pass = tech.GetPass(0);
                // set the highlight mask texture
                int size = TerrainManager.Instance.PageSize;
                pass.VertexProgramParameters.SetNamedConstant("pageSize", new Vector3(size * TerrainManager.oneMeter, size * TerrainManager.oneMeter, size * TerrainManager.oneMeter));
                if (highlightType != TerrainPage.PageHilightType.None)
                {
                    pass.GetTextureUnitState(11).SetTextureName(highlightMask.Name);
                }
                //Page.SetShadeMask(hilightMaterial, 4);

                int pageSize = TerrainManager.Instance.PageSize;

                for (int index = 0; index < AlphaSplatTerrainConfig.NUM_ALPHA_MAPS; index++)
                {
                    TextureMosaic alphaMap = config.GetAlphaMap(index);
                    if (alphaMap != null)
                    {
                        // pass in the alpha texture names and the texture coord adjustment params.
                        // The coord adjustment params are used to convert from a page relative texture
                        // coordinate to the appropriate coords for the alpha texture.
                        float  u1, u2, v1, v2;
                        string alphaTextureName = alphaMap.GetTexture(
                            pageX * pageSize, pageZ * pageSize, pageSize, pageSize,
                            out u1, out v1, out u2, out v2);

                        pass.GetTextureUnitState(index).SetTextureName(alphaTextureName);

                        string coordAdjustParam = "alpha" + index + "TextureCoordAdjust";
                        pass.VertexProgramParameters.SetNamedConstant(
                            coordAdjustParam, new Vector4(u1, u2 - u1, v1, v2 - v1));

                        //todo: Disabled page logging because it slows down terrain edits
                        // in the terrain editor.  We should probably make this
                        // logging be conditional. -Trev 9/4/08
//                        LogManager.Instance.Write("page[{0},{1}]: {2} : ({3},{4}) : ({5},{6})", pageX, pageZ,
//                                                  alphaTextureName, u1, v1, u2, v2);
                    }
                }
            }

            config.UpdateMaterial(material);

            material.Load();
            material.Lighting = true;

            dirty = false;
        }