/// <summary> /// Initialize a copy of the state /// </summary> /// <param name="copyFrom"></param> public VoxelModelState(VoxelModelState copyFrom) : this() { _parentModel = copyFrom._parentModel; Name = copyFrom.Name; BoundingBox = copyFrom.BoundingBox; for (int i = 0; i < _parentModel.Parts.Count; i++) { PartsStates.Add(new VoxelModelPartState(copyFrom.PartsStates[i])); } }
/// <summary> /// Changes current instance active state /// </summary> /// <param name="state"></param> public void SetState(VoxelModelState state) { _currentState = state; // create a copy because we can to change its values // inside the instance _internalState = new VoxelModelState(state); OnStateChanged(); }
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); }