Inheritance: MonoBehaviour
        private void ClassicMaterial()
        {
            TerrainLayer ly = editData.layers[_selectProcedural];

            if (ly.texture != null)
            {
                GUILayout.Label("Modify", PGUIStyle.nodeLabelBold);
                GUILayout.BeginHorizontal("Box");
                GUILayout.Label(PResourceManager.LoadTexture("Terrain/TDiff.jpg"));
                ly.texture =
                    EditorGUILayout.ObjectField(ly.texture, typeof(Texture2D), true, GUILayout.Width(75),
                                                GUILayout.Height(75)) as Texture;

                TerrainObject tobj = currentSelect.GetComponent <TerrainObject>();
                tobj.material.SetTexture("_Splat" + _selectProcedural, ly.texture);
                if (tobj.material.HasProperty("_BumpSplat" + _selectProcedural))
                {
                    GUILayout.Label(PResourceManager.LoadTexture("Terrain/TBump.jpg"));
                    ly.bumpTexture =
                        EditorGUILayout.ObjectField(ly.bumpTexture, typeof(Texture2D), true, GUILayout.Width(75),
                                                    GUILayout.Height(75)) as Texture;
                    tobj.material.SetTexture("_BumpSplat" + _selectProcedural, ly.bumpTexture);
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
        }
Exemplo n.º 2
0
        public void InstantiateCubes(List <TerrainData_Full> list)
        {
            List <TerrainData_Full> SurfaceDataFullList = list;

            foreach (TerrainData_Full data in SurfaceDataFullList)
            {
                Vector3 cubeLoc = new Vector3(data.gridLocX, data.gridLocZ, data.gridLocY);

                if (!surfacesTop.ContainsKey(cubeLoc))
                {
                    GameObject GodNode = _CubeBuilder.BuildMeAFuckingCube(data);

                    TerrainObject newScript = GodNode.GetComponent <TerrainObject> ();

                    GodNode.transform.eulerAngles = new Vector3(GodNode.transform.eulerAngles.x, GetAngle(newScript.cubeRot), 0);
                    GodNode.transform.SetParent(this.transform);
                    int sizeOfCubes = _mapSettings.sizeOfCubes;
                    GodNode.transform.localScale = new Vector3(sizeOfCubes, sizeOfCubes, sizeOfCubes);
                    Vector3 worldLoc = (Vector3)_GridManager.GridLocToWorldLocLookup [cubeLoc];
                    GodNode.transform.position = worldLoc;

                    surfacesTop.Add(cubeLoc, newScript);
                }
            }
        }
        void createterrain(int height = 5)
        {
            ///Create the Terrain Object
            ///Controls how the heigh map is loaded
            TerrainObject to = new TerrainObject(GraphicFactory, "..\\Content\\Textures\\hmap", new Vector3(0, -30, 0), Matrix.Identity, MaterialDescription.DefaultBepuMaterial(), 3, 3, height);

            ///Create the Model using the Terrain Object. Here we pass the textures used
            TerrainModel stm = new TerrainModel(GraphicFactory, to, "TerrainName", "..\\Content\\Textures\\Terraingrass");

            stm.SetTexture("..\\Content\\Textures\\Terraingrass", TextureType.DIFFUSE);
            ForwardXNABasicShader shader    = new ForwardXNABasicShader();
            ForwardMaterial       fmaterial = new ForwardMaterial(shader);

            ///The object itself
            obj = new IObject(fmaterial, stm, to);
            ///Add to the world
            this.World.AddObject(obj);

            ///light =p
            shader.BasicEffect.EnableDefaultLighting();
            shader.BasicEffect.SpecularPower          = 250;
            shader.BasicEffect.PreferPerPixelLighting = true;


            //Fog =P
            shader.BasicEffect.FogEnabled = true;
            shader.BasicEffect.FogColor   = new Vector3(0.1f, 0.1f, 0.1f); // Dark grey
            shader.BasicEffect.FogStart   = 30;
            shader.BasicEffect.FogEnd     = 300;
        }
Exemplo n.º 4
0
    //creates (instantiates) a terrain chunk (but does not render it yet)
    public void CreateChunk(LODPos pos, bool render)
    {
        //if the chunk has aready been created, dont build it again!
        if (chunks.ContainsKey(pos))
        {
            return;
        }

        totalChunks++;

        //build the terrainobject and add its gameobject to the chunks list(may remove this last thing later)
        //TerrainObject chunk = Build.buildObject<TerrainObject>(pos.toVector3(), Quaternion.identity);
        GameObject terrainGO = Pool.getTerrain();

        terrainGO.name = "Terrain Chunk " + pos.ToString();
        TerrainObject chunk = terrainGO.GetComponent <TerrainObject>();

        chunk.init(pos, planet);
        chunks.Add(pos, chunk);
        //Debug.Log("chunks added key :" + pos.ToString());
        visChunks.Add(pos);

        if (render)
        {
            chunk.calculateNoise();
            chunk.Render();            //renders the chunk immediately
        }
        //RequestSystem.terrainToRender.Add(chunk);
    }
Exemplo n.º 5
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            ///Create the Terrain Object
            ///Controls how the heigh map is loaded
            TerrainObject to = new TerrainObject(factory, "..\\Content\\Textures\\Untitled", Vector3.Zero, Matrix.Identity, MaterialDescription.DefaultBepuMaterial(), 1, 1, 10);
            ///Create the Model using the Terrain Object. Here we pass the textures used, in our case we are using MultiTextured Terrain so we pass lots of textures
            TerrainModel stm = new TerrainModel(factory, to, "TerrainName", "..\\Content\\Textures\\Terraingrass");

            stm.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green), TextureType.DIFFUSE);
            ///Create the shader
            ///In this sample we passed lots of textures, each one describe a level in the terrain, the ground is the sand and grass. the hills are rocks and the "mountains" are snow
            ///They are interpolated in the shader, you can control how using the shader parameters exposed in the DeferredTerrainShader
            ForwardXNABasicShader shader = new ForwardXNABasicShader();
            ///Deferred material
            ForwardMaterial fmaterial = new ForwardMaterial(shader);
            ///The object itself
            IObject obj = new IObject(fmaterial, stm, to);

            ///Add to the world
            this.World.AddObject(obj);

            shader.BasicEffect.EnableDefaultLighting();

            CameraFirstPerson cam = new CameraFirstPerson(GraphicInfo.Viewport);

            this.World.CameraManager.AddCamera(cam);
        }
Exemplo n.º 6
0
Arquivo: Pool.cs Projeto: samhogan/AUG
 public static void deleteTerrain(TerrainObject obj)
 {
     obj.reset();
     obj.gameObject.SetActive(false);
     obj.gameObject.name = "pooled terrain";
     pooledTerrain.Add(obj.gameObject);
     //GameObject.Destroy(obj.gameObject);
 }
Exemplo n.º 7
0
        private void SetScriptFields(TerrainData_Full data, TerrainObject script)
        {
            script.cubeUniqueID = data.cubeUniqueID;

            script.gridLocX = data.gridLocX;
            script.gridLocZ = data.gridLocZ;
            script.gridLocY = data.gridLocY;

            script.cubeLandType  = data.cubeLandType;
            script.cubeList      = data.cubeList;
            script.cubeType      = data.cubeType;
            script.cubeRot       = data.cubeRot;
            script.cubeSlopeType = data.cubeSlopeType;

            script.objReplaceable  = data.objReplaceable;
            script.objDestructable = data.objDestructable;

            script.objList = data.objList;
            script.objType = data.objType;
            script.objRot  = data.objRot;

            script.health = data.health;
            script.Growth = data.Growth;

            script.surfaceTop    = data.surfaceTop;
            script.surfaceBottom = data.surfaceBottom;

            script.cubeSetActive = data.cubeSetActive;

            script.inSight = data.inSight;

            script.neighVects = data.neighVects;

            script._01 = data._01;
            script._03 = data._03;
            script._04 = data._04;
            script._05 = data._05;
            script._07 = data._07;
            script._09 = data._09;
            script._10 = data._10;
            script._11 = data._11;
            script._12 = data._12;
            script._14 = data._14;
            script._15 = data._15;
            script._16 = data._16;
            script._17 = data._17;
            script._19 = data._19;
            script._21 = data._21;
            script._22 = data._22;
            script._23 = data._23;
            script._25 = data._25;

            script.sunRiseVect = _SunManager.sunRiseVect;
            script.sunMidVect  = _SunManager.sunMidVect;
            script.sunSetVect  = _SunManager.sunSetVect;

            script.terrainData = data;
        }
Exemplo n.º 8
0
    //deletes all pieces of the given chunk and reactivates it or "combines" all its pieces into it
    public void combineChunk(LODPos pos)
    {
        //reactivate the chunk
        chunks[pos].gameObject.SetActive(true);
        //Debug.Log(pos.ToString() + " was activated");


        //now find all of its pieces and destroy them

        //1 level lower
        int newLev = pos.level - 1;
        //the position of the first subchunk in this chunk
        WorldPos newStart = new WorldPos(pos.x * 2, pos.y * 2, pos.z * 2);

        for (int x = 0; x <= 1; x++)
        {
            for (int y = 0; y <= 1; y++)
            {
                for (int z = 0; z <= 1; z++)
                {
                    LODPos        newChunk = new LODPos(newLev, newStart.x + x, newStart.y + y, newStart.z + z);
                    TerrainObject tobj     = null;
                    if (chunks.TryGetValue(newChunk, out tobj))
                    {
                        //if the chunk to be deleted is split, combine it first
                        if (splitChunks.Contains(newChunk))
                        {
                            combineChunk(newChunk);
                        }

                        //remove it from vischunks
                        visChunks.Remove(newChunk);

                        //remove from chunkstosplitrender if it is in it
                        if (chunksToSplitRender.Contains(newChunk))
                        {
                            chunksToSplitRender.Remove(newChunk);
                        }

                        //finally remove from the chunks dictionary and utterly DESTROY IT (but it will later be pooled
                        chunks.Remove(newChunk);
                        //Object.Destroy(tobj);
                        Pool.deleteTerrain(tobj);
                        //Debug.Log("chunk " + newChunk.ToString() + " was deleted");
                    }
                }
            }
        }

        chunks[pos].isSplit = false;
        if (chunksToSplitRender.Contains(pos))
        {
            chunksToSplitRender.Remove(pos);
        }
        //move this from splitchunks to vischunks
        splitChunks.Remove(pos);
        visChunks.Add(pos);
    }
Exemplo n.º 9
0
    // Use this for initialization


    void Start()
    {
        rig2d        = GetComponent <Rigidbody2D>(); //Enables the RigidBody2d component
        animy        = GetComponent <Animator>();    //Allows the animator to work
        Block        = FindObjectOfType <TerrainObject>();
        RealMaxspeed = maxspeed;
        stopjump.Start();
        stopwatch.Start();
    }
Exemplo n.º 10
0
        public void Create(VertexGenerator vg, Vector3 origin)
        {
            //Track the angle we are currenlty on
            TerrainAngle = vg.CurrentTerrainRule.Angle;

            //Create the front mesh and populate our key verts for the front plane
            MeshPiece mp = new MeshPiece(vg, MeshPiece.Plane.Front, settings);

            mp.PopulateKeyVerticies(MeshPiece.Plane.Front);

            //Now create the mesh
            mp.Create(origin, TerrainAngle);


            //The first mesh could be null if we are below the minimum verticies we need to create a plane
            if (mp.MeshObject != null)
            {
                //Create a placeholder object for our mesh pieces
                InstantiateTerrainObject();

                //if (meshCollider == null) {
                //    meshCollider = TerrainObject.AddComponent<MeshCollider>();
                //    meshCollider.convex = true;
                //}

                if (terrainCollider == null)
                {
                    terrainCollider          = TerrainObject.AddComponent <TerrainCollider>();
                    terrainCollider.material = new PhysicMaterial();
                }

                //And add the front plane mesh piece to our list of meshes in the terrain piece
                MeshPieces.Add(mp);


                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece mpDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    mpDetail.Create(origin + settings.DetailPlaneOffset, TerrainAngle, mp.KeyTopVerticies);
                    MeshPieces.Add(mpDetail);
                }



                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    MeshPiece mpTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);
                    mpTop.Create(mp.StartTopMesh, TerrainAngle, mp.KeyTopVerticies);
                    MeshPieces.Add(mpTop);
                }



                //Just to tidy up the heirarchy
                ParentMeshesToTerrainObject();
            }
        }
Exemplo n.º 11
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(true, GraphicInfo);

            Texture2D   tMap = factory.GetTexture2D("Textures//hmap_10243");
            QuadTerrain q    = new PloobsEngine.Material.QuadTerrain(factory, tMap, 33, 513, 10, 3f);

            DeferredTerrainMaterial mat = new DeferredTerrainMaterial(q);

            //Set various terrain stats.
            mat.diffuseScale      = q.flatScale / 4;
            mat.detailScale       = q.flatScale / 100;
            mat.detailMapStrength = 2;
            mat.textureBlend      = factory.GetTexture2D("Textures//hmap_256blend");
            mat.textureDetail     = factory.GetTexture2D("Textures//coolgrass2DOT3");
            mat.textureRed        = factory.GetTexture2D("Textures//TexR");
            mat.textureGreen      = factory.GetTexture2D("Textures//TexG");
            mat.textureBlue       = factory.GetTexture2D("Textures//TexB");
            mat.textureBlack      = factory.GetTexture2D("Textures//TexBase");

            TerrainObject to = new TerrainObject(factory, Vector3.Zero, Matrix.Identity, q.getHeightMap(), MaterialDescription.DefaultBepuMaterial());

            IObject obj3 = new IObject(mat, null, to);

            this.World.AddObject(obj3);

            LightThrowBepu lt = new LightThrowBepu(this.World, factory);

            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion


            this.World.CameraManager.AddCamera(CameraFirstPerson);
            CameraFirstPerson.FarPlane = 20000;

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);
        }
Exemplo n.º 12
0
    public List <TerrainObject> CreateTerrainObject(int length, TerrainObject tObj)
    {
        List <TerrainObject> newTerrainObject = new List <TerrainObject>();

        for (int i = 0; i < length; i++)
        {
            newTerrainObject.Add(tObj);
        }
        return(newTerrainObject);
    }
Exemplo n.º 13
0
 public GridTileOccupant(GameObject obj, Vector3 position, Quaternion rotation, Vector3 scale, OccupantType type)
 {
     this.obj                  = obj;
     this.position             = position;
     this.rotation             = rotation;
     this.scale                = scale;
     this.terrainObject        = obj.GetComponent <TerrainObject>();
     this.windEffectController = obj.GetComponent <WindEffectController>();
     this.type                 = type;
 }
Exemplo n.º 14
0
 // Constructor, it will be passed the grid location that the tile will be set to.
 public Tile(Point passedGridLocation, int passedObject, GroundType passedGroundType)
 {
     tObject            = null;
     this.GridPosition  = passedGridLocation;
     this.FloorType     = passedGroundType;
     this.DrawPosition  = new Point(this.GridPosition.X * GetTileSize().X, this.GridPosition.Y * GetTileSize().Y);
     this.DrawRectangle = new Rectangle(this.DrawPosition, GetTileSize());
     this.tileEffects   = SpriteEffects.None;
     if (this.FloorType == GroundType.Water)
     {
         this.IsCollider = true;
     }
 }
Exemplo n.º 15
0
        public TerrainModel(GraphicFactory factory, TerrainObject terrainObject, String TerrainName, String BaseTexture, String NivelBaixo = null, String NivelMedio = null, String NivelAlto = null)
            : base(factory, TerrainName, false)
        {
            this.terrainObject = terrainObject;

            LoadModelo(factory);

            TextureInformations[0][0].SetTexture(BaseTexture, TextureType.MULTITEX1);
            TextureInformations[0][0].SetTexture(NivelBaixo, TextureType.MULTITEX2);
            TextureInformations[0][0].SetTexture(NivelMedio, TextureType.MULTITEX3);
            TextureInformations[0][0].SetTexture(NivelAlto, TextureType.MULTITEX4);
            TextureInformations[0][0].SetTexture(terrainObject.HeightMap, TextureType.HEIGHTMAP);
        }
Exemplo n.º 16
0
        private GameObject CreateGhost(TerrainObject selectedPrefab, Vector3 pos)
        {
            UnityGraph.LogGameObject(selectedPrefab.gameObject);
            ResourceDispenser dispenser = selectedPrefab.GetComponent <ResourceDispenser>();
            GameObject        obj       = GameObject.Instantiate(dispenser.AnimatedTransform.GetChild(0).gameObject);

            obj.layer = Globals.inst.layerTrigger;
            foreach (var collider in obj.GetComponentsInChildren <MeshCollider>())
            {
                collider.enabled = false;
            }
            return(obj);
        }
Exemplo n.º 17
0
    public void DetermineAnimationParameters()
    {
        terrainObject = GetComponent <TerrainObject>();
        objectMesh    = GetComponent <MeshFilter>().mesh;
        TreeAnimationController treeAnimationController = TreeAnimationController.instance;

        vertices = objectMesh.vertices;
        terrainObject.animationNumber = treeAnimationController.meshVertices.Count;
        treeAnimationController.meshVertices.Add(objectMesh.vertices);

        List <float> randomValues = new List <float>();

        for (int i = 0; i < vertices.Length; i++)
        {
            randomValues.Add((float)rand.NextDouble());
        }

        treeAnimationController.randomValues.Add(randomValues);

        int sum = 0;

        foreach (int submesh in terrainObject.numVerticesPerObject)
        {
            sum += submesh;
        }

        totalObjects = vertices.Length / sum;
        List <List <int> > vertPosPerObject = new List <List <int> >();

        for (int i = 0; i < totalObjects; i++)
        {
            List <int> objectVertPos = new List <int>();
            for (int j = 0; j < terrainObject.numVerticesPerObject.Count; j++)
            {
                int add = 0;
                for (int l = 0; l < j; l++)
                {
                    int a = terrainObject.numVerticesPerObject[l];
                    add += totalObjects * a;
                }
                for (int k = 0; k < terrainObject.numVerticesPerObject[j]; k++)
                {
                    int vertPos = k + add + i * terrainObject.numVerticesPerObject[j];
                    objectVertPos.Add(k + add + i * terrainObject.numVerticesPerObject[j]);
                }
            }
            vertPosPerObject.Add(objectVertPos);
        }

        treeAnimationController.vertPosPerObject.Add(vertPosPerObject);
    }
Exemplo n.º 18
0
        /// <summary>
        /// Load content for the screen.
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            RasterizerState          = new RasterizerState();
            RasterizerState.FillMode = FillMode.WireFrame;

            ///Forward Shader (look at this shader construction for more info)
            TerrainMaterial material = new TerrainMaterial(factory, "Terrain//HeightMap");
            ///The object itself
            TerrainObject to  = new TerrainObject(factory, Vector3.Zero, Matrix.Identity, material.Model.GetHeights(), MaterialDescription.DefaultBepuMaterial());
            IObject       obj = new IObject(material, null, to);

            ///Add to the world
            this.World.AddObject(obj);

            ///add a camera
            RotatingCamera cam = new RotatingCamera(this, new Vector3(-200, -100, -300));

            this.World.CameraManager.AddCamera(cam);

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubeMap");

            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);


            {
                Texture2D   t           = factory.CreateTexture2DColor(1, 1, Color.Red);
                SimpleModel simpleModel = new SimpleModel(factory, "Model/block");
                simpleModel.SetTexture(t);
                ///Forward Shader (look at this shader construction for more info)
                ForwardXNABasicShader shader = new ForwardXNABasicShader();
                ///Forward material
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        ///Physic info (position, rotation and scale are set here)
                        BoxObject tmesh = new BoxObject(new Vector3(j * 10 + 200, 100, i * 10 + 200), 1, 1, 1, 10, Vector3.One * 2, Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
                        ///The object itself
                        obj = new IObject(fmaterial, simpleModel, tmesh);
                        ///Add to the world
                        this.World.AddObject(obj);
                        objs.Add(obj);
                        tmesh.isMotionLess = true;
                    }
                }
                shader.BasicEffect.EnableDefaultLighting();
            }
        }
    /// <summary>
    /// Asynchron method for loading the sandbox.
    /// </summary>
    private IEnumerator loadSandbox()
    {
        this.menuCanvasGroup.blocksRaycasts = false;
        this.startSandboxButton.SetActive(false);

        TerrainObject terrain = GameObject.Find("Plane").GetComponent <TerrainObject>();

        yield return(null);

        terrain.generateMeshHeights();

        this.closeMainMenu();
        yield return(null);
    }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);


            Picking picking = new Picking(this);

            this.AddScreenUpdateable(picking);

            perlim = factory.CreateTexture2DPerlinNoise(512, 512, 0.03f, 3f, 0.5f, 1);
            to     = new TerrainObject(factory, perlim, Vector3.Zero, Matrix.Identity, MaterialDescription.DefaultBepuMaterial(), 2, 2);
            //TerrainObject to = new TerrainObject(factory,"..\\Content\\Textures\\Untitled",Vector3.Zero,Matrix.Identity,MaterialDescription.DefaultBepuMaterial(),2,1);
            TerrainModel          stm    = new TerrainModel(factory, to, "TerrainName", "..\\Content\\Textures\\Terraingrass", "..\\Content\\Textures\\rock", "..\\Content\\Textures\\sand", "..\\Content\\Textures\\snow");
            DeferredTerrainShader shader = new DeferredTerrainShader(TerrainType.MULTITEXTURE);
            DeferredMaterial      mat    = new DeferredMaterial(shader);
            IObject obj3 = new IObject(mat, stm, to);

            this.World.AddObject(obj3);



            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion

            this.World.CameraManager.AddCamera(new CameraFirstPerson(true, GraphicInfo));

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);

            ///O PICKING FUNCIONA APENAS COM OBJETOS QUE TENHAM CORPO FISICO REAL !!!
            ///OS GHOST E OS DUMMY NUNCA SERAO SELECIONADOS
            ///Para ser informado a todo frame sobre as colisoes do raio, basta utilizar o outro construtor
            picking.OnPickedLeftButton += new OnPicked(onPick);
        }
Exemplo n.º 21
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            ///Create the Terrain Object
            ///Controls how the heigh map is loaded
            TerrainObject to = new TerrainObject(factory, "..\\Content\\Textures\\Untitled", Vector3.Zero, Matrix.Identity, MaterialDescription.DefaultBepuMaterial(), 2, 1);
            ///Create the Model using the Terrain Object. Here we pass the textures used, in our case we are using MultiTextured Terrain so we pass lots of textures
            TerrainModel stm = new TerrainModel(factory, to, "TerrainName", "..\\Content\\Textures\\Terraingrass", "..\\Content\\Textures\\rock", "..\\Content\\Textures\\sand", "..\\Content\\Textures\\snow");
            ///Create the shader
            ///In this sample we passed lots of textures, each one describe a level in the terrain, the ground is the sand and grass. the hills are rocks and the "mountains" are snow
            ///They are interpolated in the shader, you can control how using the shader parameters exposed in the DeferredTerrainShader
            DeferredTerrainShader shader = new DeferredTerrainShader(TerrainType.MULTITEXTURE);
            ///the classic material
            DeferredMaterial mat  = new DeferredMaterial(shader);
            IObject          obj3 = new IObject(mat, stm, to);

            this.World.AddObject(obj3);

            lt = new LightThrowBepu(this.World, factory);

            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion

            CameraFirstPerson cam = new CameraFirstPerson(MathHelper.ToRadians(30), MathHelper.ToRadians(-10), new Vector3(200, 150, 250), GraphicInfo);
            this.World.CameraManager.AddCamera(cam);

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//grassCube");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);

            this.RenderTechnic.AddPostEffect(new AntiAliasingPostEffectStalker());
        }
Exemplo n.º 22
0
        private void UpdateTerrainComponent()
        {
            if (editData.nbrTerrainObject == 0)
            {
                TerrainObject _child = editData.defaultChild.gameObject.GetComponent <TerrainObject>();

                _child.enabledLODSystem = editData.activateLOD;
                _child.enabledBillboard = editData.activateBillboard;
                _child.enabledLayerCul  = editData.activateLayerCul;
                _child.closeView        = editData.closeView;
                _child.normalView       = editData.normalView;
                _child.farView          = editData.farView;
                _child.backgroundView   = editData.backgroundView;
                _child.master           = 1;
            }
        }
Exemplo n.º 23
0
    public void RemoveTerrainObject(HexCoordinates coordinates)
    {
        //TODO this could be more efficient
        CellStack stack = GetCellStackFromWorldCoords(coordinates);

        if (stack)
        {
            Vector2Int    index = stack.indexWithinChunk;
            TerrainObject obj   = terrainObjects[index.x, index.y];
            if (obj != null)
            {
                terrainObjects[index.x, index.y] = null;
                GameObject.Destroy(obj.gameObject);
            }
        }
    }
Exemplo n.º 24
0
    public void GenerateObjects(TerrainObject objectInfo)
    {
        cleanUpObjects();

        int width  = heightMap.GetLength(0);
        int height = heightMap.GetLength(1);

        NoiseParameters noiseParameters = objectInfo.noise;

        float[,] noiseMap = Noise.GenerateNoiseMap(width, height, Random.Range(0, int.MaxValue),
                                                   noiseParameters.noiseScale, noiseParameters.octaves, noiseParameters.persistance, noiseParameters.lacunarity, Vector2.zero);

        float startHeight = heightCurve.Evaluate(objectInfo.startHeight) * heightMultiplier;
        float endHeight   = heightCurve.Evaluate(objectInfo.endHeight) * heightMultiplier;

        for (int j = 0; j < height; j++)
        {
            for (int i = 0; i < width; i++)
            {
                float y = heightCurve.Evaluate(heightMap[i, j]) * heightMultiplier;
                if (y >= startHeight && y <= endHeight && noiseMap[i, j] > objectInfo.noiseThreshold)
                {
                    Vector3 pos = new Vector3((width - 1) / -2f + i, y, (height - 1) / 2f - j) * uniformScale;
                    pos += new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)) * 0.2f;
                    pos += transform.position;

                    IslandObject obj = Instantiate(objectInfo.prefab, pos, Quaternion.identity);
                    obj.transform.SetParent(objectContainer, true);
                    obj.Generate();

                    // Align the rotation of the object to the normal of the terrain at that point
                    if (objectInfo.alignToNormal)
                    {
                        Ray        ray = new Ray(pos + Vector3.up * 10, Vector3.down);
                        RaycastHit hitInfo;
                        bool       hit = mesh.meshCollider.Raycast(ray, out hitInfo, Mathf.Infinity);

                        if (hit)
                        {
                            obj.transform.up = hitInfo.normal;
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 25
0
    /*
     * void OnTriggerEnter2D(Collider2D other) {
     *
     *  // Check if there is a terrain object that is blocking the path on this tile
     *  TerrainObject terrainObj = other.GetComponent<TerrainObject>();
     *  if(terrainObj)
     *  {
     *      // If the terrain object is a barrier, then this tile is not patheable
     *      isPatheable = !terrainObj.isBarrier;
     *  }
     *
     * }
     */

    /// <summary>
    /// Automatically detects if there is a barrier terrain object on this tile
    /// setting the isPatheable field accordingly.
    ///
    /// To use right-click isPatheable field and select "Set Patheable"
    /// </summary>
    private void SetPatheable()
    {
        bool       cleanUpCollider = false; // Checks to see if we should remove temporarily created collider
        Collider2D tileCollider    = GetComponent <Collider2D>();

        if (tileCollider == null)
        {
            // Create a temporary collider to raycast from
            cleanUpCollider = true;
            tileCollider    = gameObject.AddComponent <BoxCollider2D>();
        }

        // Create raycast to see if there are any barriers on this tile
        RaycastHit2D[] results = Physics2D.BoxCastAll(transform.position, new Vector2(0.98f, 0.98f), 0, Vector2.zero, 0);

        //Debug.Log("Num col: " + results.Length);

        isPatheable = true;

        // If there were any collision, then check if colliding object is a terrain barrier
        if (results.Length > 0)
        {
            //check if each collider is a barrier
            for (int i = 0; i < results.Length; i++)
            {
                TerrainObject terrainObj = results[i].collider.GetComponent <TerrainObject>();

                //Debug.Log(results[i].collider.gameObject.name);
                if (terrainObj)
                {
                    if (terrainObj.isBarrier)
                    {
                        isPatheable = false;
                        break;
                    }
                }
            }
        }

        if (cleanUpCollider)
        {
            // Clean up temporary collider
            DestroyImmediate(tileCollider);
        }
    }
Exemplo n.º 26
0
        private TerrainObject ParseTerrainObject(JObject currentGameObject, GameObject parent = null)
        {
            var name      = JSONHelper.GetValue("Name", currentGameObject);
            var model     = JSONHelper.GetValue("Model", currentGameObject);
            var IsEnabled = JSONHelper.ToBool(JSONHelper.GetValue("isEnabled", currentGameObject));

            var mod        = ToylandSiege.GetInstance().Content.Load <Model>(model);
            var terrainObj = new TerrainObject(name, mod);

            terrainObj.IsEnabled    = IsEnabled;
            terrainObj.IsStatic     = true;
            terrainObj.IsCollidable = true;
            terrainObj.Type         = JSONHelper.GetValue("Type", currentGameObject);
            terrainObj.Parent       = parent;

            if (JSONHelper.ValueExist("Position", currentGameObject))
            {
                terrainObj.Position = JSONHelper.ParseVector3(currentGameObject.GetValue("Position"));
            }

            if (JSONHelper.ValueExist("Rotation", currentGameObject))
            {
                terrainObj.Rotation = JSONHelper.ParseVector3(currentGameObject.GetValue("Rotation"));
            }

            if (JSONHelper.ValueExist("Scale", currentGameObject))
            {
                terrainObj.Scale = JSONHelper.ParseVector3(currentGameObject.GetValue("Scale"));
            }
            terrainObj.CreateTransformationMatrix();

            if (JSONHelper.ValueExist("Child", currentGameObject))
            {
                for (int i = 0; i < currentGameObject.GetValue("Child").Count(); i++)
                {
                    terrainObj.AddChild(ParseGameObject(currentGameObject.GetValue("Child")[i].ToObject <JObject>(), terrainObj));
                }
            }

            // TODO: Load from a config file?
            terrainObj.Collider.BType = Collider.BoundingType.Box;
            terrainObj.Collider.RecreateBounding();

            return(terrainObj);
        }
Exemplo n.º 27
0
        internal void CheckShader()
        {
            TerrainObject curr = currentSelect.GetComponent <TerrainObject>();

            foreach (var a in TerrainShader.pool)
            {
                if (a.shader == curr.material.shader)
                {
                    shaderType = (TerrainShaderType)a.type;
                    if (curr.material.HasProperty("_Tiling"))
                    {
                        upsideTile = curr.material.GetVector("_Tiling");
                        upsideF    = curr.material.GetFloat("_UpSide");
                        blendFac   = curr.material.GetFloat("_Blend");
                    }
                }
            }
        }
Exemplo n.º 28
0
        private void AddContainerComponents(GameObject GodNode, TerrainData_Full data)
        {
            TerrainObject newTerrainScript = GodNode.AddComponent <TerrainObject>();

            SetScriptFields(data, newTerrainScript);

            foreach (SelectObject script in selectObjects)
            {
                script.terrainscript = newTerrainScript;
            }

            newTerrainScript.ConnectObjectLinks();

            BoxCollider boxColl = GodNode.AddComponent <BoxCollider> ();

            boxColl.isTrigger = true;
            Vector3 collPos = new Vector3(0, 0.5f, 0);

            boxColl.center = collPos;
        }
Exemplo n.º 29
0
    // Method that removes an occupant from a grid tile
    public void RemoveTerrainTileOccupant(GridTile tile)
    {
        for (int i = 0; i < tile.occupants.Count; i++)
        {
            // if type is Terrain Generated
            if (tile.occupants[i].type == GridTileOccupant.OccupantType.TerrainGenerated)
            {
                // Get the terrainObject script from the occupant
                TerrainObject terrainObj = tile.occupants[i].obj.GetComponent <TerrainObject>();

                // Get the submeshes that should be in this particular terrain object from the biomemeshes
                Mesh[] objMeshes = thisTerrainController.biomeMeshes[terrainObj.biome].mesh[terrainObj.objectNR];

                // create an object of with info of the object that should be removed

                // for each of these meshes
                for (int k = 0; k < objMeshes.Length; k++)
                {
                    Vector3 startVert = objMeshes[k].vertices[0];
                    startVert = new Vector3(startVert.x * tile.occupants[i].scale.x, startVert.y * tile.occupants[i].scale.y, startVert.z * tile.occupants[i].scale.z);
                    // scale, rotate and move the vertex according to inputs
                    startVert = tile.occupants[i].rotation * startVert;
                    startVert = startVert + (tile.occupants[i].position - terrainObj.transform.position);

                    int numVerts = objMeshes[k].vertexCount;
                    // Add a copy of the mesh that should be removed. Move, rotate and scale it as it is in the game.
                    terrainObj.RemoveMesh(new MoveMeshObj(startVert, numVerts));
                }
            }
        }

        for (int i = 0; i < tile.occupants.Count; i++)
        {
            // if type is Terrain Generated
            if (tile.occupants[i].type == GridTileOccupant.OccupantType.TerrainGenerated)
            {
                // set the tile occupant to null
                tile.occupants.RemoveAt(i);
            }
        }
    }
Exemplo n.º 30
0
    //generates a chunk if it will exist but first generates all chunk levels above it and subdivides them
    //returns true if the chunk is successfully created
    public bool requestChunk(LODPos pos)
    {
        //Debug.Log(pos.ToString());
        //if it is already built, we are done
        if (chunks.ContainsKey(pos))
        {
            return(true);
        }

        LODPos abovePos = getAbove(pos);

        if (chunks.ContainsKey(getAbove(pos)))
        {
            TerrainObject above = null;
            chunks.TryGetValue(abovePos, out above);

            //if it is already split, the current terrian chunk will never exist
            if (above.isSplit)
            {
                return(false);
            }
            else
            {
                //split the chunk and then check if the chunk exists now
                splitChunk(abovePos);
                return(chunks.ContainsKey(pos));
            }
        }
        else        //the above chunk does not exist
        {
            //request the above chunk to be generated, and if it is, split it and check if the current chunk is generated
            if (requestChunk(abovePos))
            {
                splitChunk(abovePos);
                return(chunks.ContainsKey(pos));
            }

            return(false);
        }
    }
	public void AddTerrainObject (TerrainObject newTerrainObject)
	{
		terrainObjects.Add(newTerrainObject);
	}
	public void RemoveTerrainObject (TerrainObject objectToRemove)
	{
		terrainObjects.Remove(objectToRemove);
	}