Beispiel #1
0
        public void AddPart(VoxelModelPart part)
        {
            foreach (var voxelModelState in States)
            {
                voxelModelState.PartsStates.Add(new VoxelModelPartState());
            }

            Parts.Add(part);
        }
Beispiel #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);
        }