/// <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])); } }
public VoxelModelInstance(VoxelModel model = null) { _rotation = Quaternion.Identity; _headRotation = Quaternion.Identity; World = Matrix.Identity; _animationIndex = -1; Alpha = 1; LightColor = new Color3(1, 1, 1); SetParentModel(model); }
/// <summary> /// This method should be used only on deserialization step to restore parent model relationship /// </summary> /// <param name="model"></param> /// <exception cref="ArgumentNullException"></exception> private void SetParentModel(VoxelModel model) { if (model == null) { throw new ArgumentNullException("model"); } VoxelModel = model; // init the cached state, cached state should have the same structure as parent model states SetState(model.GetMainState()); }
/// <summary> /// Returns world matrix to draw the tool /// </summary> /// <returns></returns> public Matrix GetToolTransform() { var armIndex = VoxelModel.GetArmIndex(); var arm = VoxelModel.GetArm(); if (armIndex == -1 || !arm.PalmTransform.HasValue) { return(Matrix.Identity); } // palmTransform value is stored only in the first state (which is returned by GetArm()) // so we can't use current state palmTrasform value return(arm.PalmTransform.Value * State.PartsStates[armIndex].GetTransformation() * Matrix.RotationQuaternion(Rotation) * World); }
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); }
public VoxelModelState(VoxelModel parentModel) : this() { ParentModel = parentModel; }
/// <summary> /// Call this method when the parent model has changed parts count (Editor use case) /// </summary> public void UpdateStates() { SetState(VoxelModel.GetMainState()); }