Exemple #1
0
        private List <LandscapeEntity> PopulateChunksWithTree(Vector3I chunkPosition, Biome biome, byte[] chunkBytes, ChunkColumnInfo[] columndInfo, FastRandom rnd)
        {
            if (biome.BiomeTrees.Trees.Count <= 0)
            {
                return(null);
            }
            //Get Rnd chunk Location.
            int x = rnd.Next(0, 16);
            int z = rnd.Next(0, 16);
            int y = columndInfo[x * AbstractChunk.ChunkSize.Z + z].MaxGroundHeight + 1;

            //Validate position = Must be Air block (not water) !
            if (chunkBytes[((z * AbstractChunk.ChunkSize.X) + x) * AbstractChunk.ChunkSize.Y + y] != WorldConfiguration.CubeId.Air)
            {
                return(null);
            }

            x += (chunkPosition.X * AbstractChunk.ChunkSize.X);
            z += (chunkPosition.Z * AbstractChunk.ChunkSize.Z);
            Vector3I worldPosition = new Vector3I(x, y, z);

            //Generate Tree mesh !
            //Get tree type following distribution chances inside the biome
            TreeBluePrint treeType       = biome.BiomeTrees.GetTreeTemplate(rnd, _worldParameters.Configuration.TreeBluePrintsDico);
            int           generationSeed = rnd.Next();

            return(LandscapeEntityParser.GlobalMesh2ChunkMesh(_treeGenerator.Generate(generationSeed, worldPosition, treeType), worldPosition, treeType.Id, generationSeed));
        }
Exemple #2
0
        public static VoxelModel GenerateTreeModel(int seed, TreeBluePrint blueprint, TreeLSystem treeSystem = null)
        {
            if (treeSystem == null)
            {
                treeSystem = new TreeLSystem();
            }

            var blocks = treeSystem.Generate(seed, new Vector3I(), blueprint);

            var max = new Vector3I(int.MinValue);
            var min = new Vector3I(int.MaxValue);

            foreach (var blockWithPosition in blocks)
            {
                max = Vector3I.Max(max, blockWithPosition.WorldPosition);
                min = Vector3I.Min(min, blockWithPosition.WorldPosition);
            }

            var size  = max - min + Vector3I.One;
            var model = new VoxelModel();

            model.Name                        = "Tree Example";
            model.ColorMapping                = new ColorMapping();
            model.ColorMapping.BlockColors    = new Color4[64];
            model.ColorMapping.BlockColors[0] = Color.Brown.ToColor4();
            model.ColorMapping.BlockColors[1] = Color.Green.ToColor4();

            var frame = new VoxelFrame(size);

            foreach (var blockWithPosition in blocks)
            {
                frame.BlockData.SetBlock(blockWithPosition.WorldPosition - min, blockWithPosition.BlockId == blueprint.TrunkBlock ? (byte)1 : (byte)2);
            }

            model.Frames.Add(frame);
            var part = new VoxelModelPart();

            part.Name = "Main";
            model.Parts.Add(part);

            var state = new VoxelModelState(model);

            state.Name = "Default";
            state.PartsStates[0].Translation = new Vector3(min.X, 0, min.Z);
            model.States.Add(state);

            return(model);
        }
Exemple #3
0
        public override void FTSUpdate(GameTime timeSpent)
        {
            if (_inputManager.ActionsManager.isTriggered(Actions.EngineReserved1))
            {
                rotationQ.ValuePrev = rotationQ.Value;
                _withRotation       = !_withRotation;
            }

            if (_inputManager.ActionsManager.isTriggered(Actions.EngineReserved2))
            {
                if (_newTemplate != null)
                {
                    RefreshBuffers(_newTemplate);
                }
            }

            if (Pipe.MessagesQueue.Count > 0)
            {
                TreeBluePrint newBluePrint;
                if (Pipe.MessagesQueue.TryDequeue(out newBluePrint))
                {
                    _newTemplate = newBluePrint;
                    RefreshBuffers(_newTemplate);
                }
            }

            if (_withRotation)
            {
                rotation += 0.01f;
            }

            rotationQ.BackUpValue();
            rotationQ.Value = Quaternion.RotationAxis(Vector3.UnitY, rotation);
            if (rotation >= MathHelper.TwoPi)
            {
                rotation = 0;
            }
            if (rotation <= -MathHelper.TwoPi)
            {
                rotation = 0;
            }
        }
Exemple #4
0
        public void Start()
        {
            PipeStream = new NamedPipeClientStream(".", "UtopiaEditor", PipeDirection.InOut, PipeOptions.Asynchronous);
            PipeStream.Connect(1000);
            if (PipeStream.IsConnected)
            {
                using (StreamReader sr = new StreamReader(PipeStream))
                {
                    while (StopThread != true)
                    {
                        string data = sr.ReadLine();
                        if (data != null)
                        {
                            data = data.Replace("|", Environment.NewLine);
                            TreeBluePrint BleuPrintdata = (TreeBluePrint)XmlSerialize.XmlDeserializeFromString(data, typeof(TreeBluePrint));
                            MessagesQueue.Enqueue(BleuPrintdata);
                        }
                        Thread.Sleep(1);
                    }
                }
            }

            PipeStream.Dispose();
        }
Exemple #5
0
        private void RefreshBuffers(TreeBluePrint treeTemplate)
        {
            FastRandom rnd      = new FastRandom();
            FastRandom rndColor = new FastRandom();
            //Generate the list of Tree points.
            List <BlockWithPosition> result = _treeSystem.Generate(rnd.Next(), new S33M3Resources.Structs.Vector3I(), treeTemplate);

            _letreeVertexCollection = new List <VertexHLSLLTree>();
            _letreeIndexCollection  = new List <ushort>();

            MaxtreeSize.X = int.MinValue;
            MaxtreeSize.Y = int.MinValue;
            MaxtreeSize.Z = int.MinValue;

            MintreeSize.X = int.MaxValue;
            MintreeSize.Y = int.MaxValue;
            MintreeSize.Z = int.MaxValue;
            //For each block
            foreach (BlockWithPosition block in result)
            {
                float blockShade   = rnd.NextFloat(0.8f, 1.0f);
                int   vertexOffset = _letreeVertexCollection.Count;
                //Create the 24 vertex + 36 Index data per cube !
                for (int i = 0; i < vertexCube.Length; i++)
                {
                    ByteColor c;
                    if (block.BlockId == treeTemplate.TrunkBlock)
                    {
                        c = Color.Brown;
                    }
                    else
                    {
                        c = Color.Green;
                    }
                    //int blue = c.B + rndColor.Next(-10, 10); if (blue < 0 || blue > 255) blue = c.B; c.B += (byte)blue;
                    //int red = c.R + rndColor.Next(-10, 10); if (red < 0 || red > 255) red = c.R; c.R += (byte)red;
                    //int green = c.G + rndColor.Next(-10, 10); if (green < 0 || green > 255) blue = c.G; c.G += (byte)green;
                    if (block.WorldPosition.X > MaxtreeSize.X)
                    {
                        MaxtreeSize.X = block.WorldPosition.X;
                    }
                    if (block.WorldPosition.Y > MaxtreeSize.Y)
                    {
                        MaxtreeSize.Y = block.WorldPosition.Y;
                    }
                    if (block.WorldPosition.Z > MaxtreeSize.Z)
                    {
                        MaxtreeSize.Z = block.WorldPosition.Z;
                    }
                    if (block.WorldPosition.X < MintreeSize.X)
                    {
                        MintreeSize.X = block.WorldPosition.X;
                    }
                    if (block.WorldPosition.Y < MintreeSize.Y)
                    {
                        MintreeSize.Y = block.WorldPosition.Y;
                    }
                    if (block.WorldPosition.Z < MintreeSize.Z)
                    {
                        MintreeSize.Z = block.WorldPosition.Z;
                    }
                    _letreeVertexCollection.Add(new VertexHLSLLTree(vertexCube[i] + block.WorldPosition, blockShade, c));
                }

                foreach (var index in indicesCube)
                {
                    _letreeIndexCollection.Add((ushort)(index + vertexOffset));
                }
            }
            _bufferDirty = true;
        }