public void TestRecreationOfChildNodeAfterRemovalByReference()
        {
            Node node = new SceneNode( this.fakeSceneManager );
            Node childNode = node.CreateChild( Name );

            node.RemoveChild( childNode );
            node.CreateChild( Name );
        }
Example #2
0
        public void Init( ref SceneNode ParentSceneNode, int tableX, int tableZ, int tileX, int tileZ )
        {
            init = true;

            Vector3 ParentPos = ParentSceneNode.DerivedPosition;

            info.PageX = tableX;
            info.PageZ = tableZ;
            info.TileX = tileX;
            info.TileZ = tileZ;
            // Calculate the offset from the parent for this tile

            Vector3 scale = Options.Instance.Scale;
            float endx = Options.Instance.TileSize * scale.x;
            float endz = Options.Instance.TileSize * scale.z;
            info.PosX = info.TileX * endx;
            info.PosZ = info.TileZ * endz;

            name = String.Format("tile[{0},{1}][{2},{3}]",info.PageX, info.PageZ, info.TileX, info.TileZ);
            tileSceneNode = (SceneNode)ParentSceneNode.CreateChild( name );

            // figure out scene node position within parent
            tileSceneNode.Position = new Vector3( info.PosX, 0, info.PosZ );

            tileSceneNode.AttachObject( this );

            float MaxHeight = Data2DManager.Instance.GetMaxHeight(info.PageX, info.PageZ);

            bounds.SetExtents( new Vector3(0,0,0) , new Vector3((float)( endx ), MaxHeight, (float)( endz )) );

            //Change Zone of this page
            boundsExt.SetExtents( new Vector3( - endx * 0.5f, - MaxHeight * 0.5f, - endz * 0.5f) , new Vector3(endx * 1.5f, MaxHeight * 1.5f , endz * 1.5f));

            //Change Zone of this page

            this.worldAABB.SetExtents( new Vector3(info.PosX + ParentPos.x ,0, info.PosZ + ParentPos.z), new Vector3((float)( info.PosX + ParentPos.x + endx), MaxHeight, (float)( info.PosZ + ParentPos.z + endz) ));
            //this.worldBounds.SetExtents( new Vector3(info.PosX + ParentPos.x ,0, info.PosZ + ParentPos.z), new Vector3((float)( info.PosX + ParentPos.x + endx), MaxHeight, (float)( info.PosZ + ParentPos.z + endz) ));

            for ( long i = 0; i < 4; i++ )
            {
                neighbors[ i ] = null;
            }
            //force update in scene node
            //tileSceneNode.update( true, true );
            tileSceneNode.NeedUpdate();
            loaded = false;
        }
        public void TestReaddingOfChildNodeAfterRemovalByName()
        {
            Node node = new SceneNode( this.fakeSceneManager );
            Node childNode = node.CreateChild( Name );

            node.RemoveChild( Name );
            node.AddChild( childNode );
        }
        public override void LoadWorldGeometry(string fileName)
        {
            TerrainOptions options = new TerrainOptions();

            DataSet optionData = new DataSet();
            optionData.ReadXml(fileName);
            DataTable table = optionData.Tables[0];
            DataRow row = table.Rows[0];

            string terrainFileName = "";
            string detailTexture = "";
            string worldTexture = "";

            if(table.Columns["Terrain"] != null)
            {
                terrainFileName = (string)row["Terrain"];
            }

            if(table.Columns["DetailTexture"] != null)
            {
                detailTexture = (string)row["DetailTexture"];
            }

            if(table.Columns["WorldTexture"] != null)
            {
                worldTexture = (string)row["WorldTexture"];
            }

            if(table.Columns["MaxMipMapLevel"] != null)
            {
                options.maxMipmap = Convert.ToInt32(row["MaxMipMapLevel"]);
            }

            if(table.Columns["DetailTile"] != null)
            {
                options.detailTile = Convert.ToInt32(row["DetailTile"]);
            }

            if(table.Columns["MaxPixelError"] != null)
            {
                options.maxPixelError = Convert.ToInt32(row["MaxPixelError"]);
            }

            if(table.Columns["TileSize"] != null)
            {
                options.size = Convert.ToInt32(row["TileSize"]);
            }

            if(table.Columns["ScaleX"] != null)
            {
                options.scalex = StringConverter.ParseFloat((string)row["ScaleX"]);
            }

            if(table.Columns["ScaleY"] != null)
            {
                options.scaley = StringConverter.ParseFloat((string)row["ScaleY"]);
            }

            if(table.Columns["ScaleZ"] != null)
            {
                options.scalez = StringConverter.ParseFloat((string)row["ScaleZ"]);
            }

            if(table.Columns["VertexNormals"] != null)
            {
                options.isLit = ((string)row["VertexNormals"]) == "yes" ? true : false;
            }

            scale = new Vector3(options.scalex, options.scaley, options.scalez);
            tileSize = options.size;

            // load the heightmap
            Image image = Image.FromFile(terrainFileName);

            // TODO: Check terrain size for 2^n + 1

            // get the data from the heightmap
            options.data = image.Data;

            options.worldSize = image.Width;

            float maxx = options.scalex * options.worldSize;
            float maxy = 255 * options.scaley;
            float maxz = options.scalez * options.worldSize;

            Resize(new AxisAlignedBox(Vector3.Zero, new Vector3(maxx, maxy, maxz)));

            terrainMaterial = CreateMaterial("Terrain");

            if(worldTexture != "")
            {
                terrainMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState(worldTexture, 0);
            }

            if(detailTexture != "")
            {
                terrainMaterial.GetTechnique(0).GetPass(0).CreateTextureUnitState(detailTexture, 1);
            }

            terrainMaterial.Lighting = options.isLit;
            terrainMaterial.Load();

            terrainRoot = (SceneNode)RootSceneNode.CreateChild("TerrainRoot");

            numTiles = (options.worldSize - 1) / (options.size - 1);

            tiles = new TerrainRenderable[numTiles, numTiles];

            int p = 0, q = 0;

            for(int j = 0; j < options.worldSize - 1; j += (options.size - 1))
            {
                p = 0;

                for(int i = 0; i < options.worldSize - 1; i += (options.size - 1))
                {
                    options.startx = i;
                    options.startz = j;

                    string name = string.Format("Tile[{0},{1}]", p, q);

                    SceneNode node = (SceneNode)terrainRoot.CreateChild(name);
                    TerrainRenderable tile = new TerrainRenderable();
                    tile.Name = name;

                    tile.SetMaterial(terrainMaterial);
                    tile.Init(options);

                    tiles[p,q] = tile;

                    node.AttachObject(tile);

                    p++;
                }

                q++;
            }

            int size1 = tiles.GetLength(0);
            int size2 = tiles.GetLength(1);

            for(int j = 0; j < size1; j++)
            {
                for(int i = 0; i < size2; i++)
                {
                    if(j != size1 - 1)
                    {
                        ((TerrainRenderable)tiles[i,j]).SetNeighbor(Neighbor.South, (TerrainRenderable)tiles[i, j + 1]);
                        ((TerrainRenderable)tiles[i,j + 1]).SetNeighbor(Neighbor.North, (TerrainRenderable)tiles[i, j]);
                    }

                    if(i != size2 - 1)
                    {
                        ((TerrainRenderable)tiles[i,j]).SetNeighbor(Neighbor.East, (TerrainRenderable)tiles[i + 1, j]);
                        ((TerrainRenderable)tiles[i + 1,j]).SetNeighbor(Neighbor.West, (TerrainRenderable)tiles[i, j]);
                    }
                }
            }

            #if NOT_USED
            if(false) // && options.isLit) //TODO: Fix
            {
                for(int j = 0; j < size1; j++)
                {
                    for(int i = 0; i < size2; i++)
                    {
                        ((TerrainRenderable)tiles[i,j]).CalculateNormals();
                    }
                }
            }
            #endif
            this.terrainOptions = options; //we need these later for GetHeightAt, so make them a member variable
        }