public bool ConstrainForward(TreeCrayon crayon, ref float distance, ref float radiusEndScale) { Matrix m = crayon.GetTransform(); if (m.Up.Y < 0.0f && m.Translation.Y + m.Up.Y*distance < limit) return false; // distance *= 100; // Use distance * 100 to visualize which branches will be cut. return true; }
/// <summary> /// Generates the structure of a tree, but no vertex data. /// </summary> /// <param name="rnd">Object providing random numbers.</param> /// <param name="userConstraint">Object imposing user-defined constraints on the generated tree. See <see cref="TreeConstraints"/>.</param> /// <returns>A new tree skeleton.</returns> /// <seealso cref="TreeSkeleton"/> /// <seealso cref="TreeMesh"/> /// <seealso cref="TreeLeafCloud"/> /// <seealso cref="SimpleTree"/> public TreeSkeleton GenerateTree(Random rnd, TreeContraints userConstraint) { if (root == null || maxLevel == 0) { throw new InvalidOperationException( "TreeGenerator has not been initialized. Must set Root and MaxLevel before generating a tree."); } var crayon = new TreeCrayon(); crayon.Level = maxLevel; crayon.BoneLevels = BoneLevels; crayon.Constraints = constraints; constraints.UserConstraint = userConstraint; crayon.Skeleton.LeafAxis = LeafAxis; crayon.Skeleton.Bones.Add(new TreeBone(Quaternion.Identity, -1, Matrix.Identity, Matrix.Identity, 1, 1, -1)); root.Execute(crayon, rnd); crayon.Skeleton.CloseEdgeBranches(); crayon.Skeleton.TextureHeight = textureHeight + textureHeightVariation * (2.0f * (float)rnd.NextDouble() - 1.0f); return(crayon.Skeleton); }
public bool ConstrainForward(TreeCrayon crayon, ref float distance, ref float radiusEndScale) { Matrix m = crayon.GetTransform(); if (m.Up.Y < 0.0f && m.Translation.Y + m.Up.Y * distance < limit) { return(false); // distance *= 100; // Use distance * 100 to visualize which branches will be cut. } return(true); }
public bool ConstrainForward(TreeCrayon crayon, ref float distance, ref float radiusEndScale) { foreach (TreeContraints c in constaints) { if (!c.ConstrainForward(crayon, ref distance, ref radiusEndScale)) return false; } if (userConstraint != null) return userConstraint.ConstrainForward(crayon, ref distance, ref radiusEndScale); return true; }
public bool ConstrainForward(TreeCrayon crayon, ref float distance, ref float radiusEndScale) { foreach (TreeContraints c in constaints) { if (!c.ConstrainForward(crayon, ref distance, ref radiusEndScale)) { return(false); } } if (userConstraint != null) { return(userConstraint.ConstrainForward(crayon, ref distance, ref radiusEndScale)); } return(true); }
/// <summary> /// Generates the structure of a tree, but no vertex data. /// </summary> /// <param name="rnd">Object providing random numbers.</param> /// <param name="userConstraint">Object imposing user-defined constraints on the generated tree. See <see cref="TreeConstraints"/>.</param> /// <returns>A new tree skeleton.</returns> /// <seealso cref="TreeSkeleton"/> /// <seealso cref="TreeMesh"/> /// <seealso cref="TreeLeafCloud"/> /// <seealso cref="SimpleTree"/> public TreeSkeleton GenerateTree(Random rnd, TreeContraints userConstraint) { if (root == null || maxLevel == 0) throw new InvalidOperationException( "TreeGenerator has not been initialized. Must set Root and MaxLevel before generating a tree."); var crayon = new TreeCrayon(); crayon.Level = maxLevel; crayon.BoneLevels = BoneLevels; crayon.Constraints = constraints; constraints.UserConstraint = userConstraint; crayon.Skeleton.LeafAxis = LeafAxis; crayon.Skeleton.Bones.Add(new TreeBone(Quaternion.Identity, -1, Matrix.Identity, Matrix.Identity, 1, 1, -1)); root.Execute(crayon, rnd); crayon.Skeleton.CloseEdgeBranches(); crayon.Skeleton.TextureHeight = textureHeight + textureHeightVariation*(2.0f*(float) rnd.NextDouble() - 1.0f); return crayon.Skeleton; }