LFTree evaluateNnary(LibFive_Operation op, params LFTree[] trees) { if (trees.Length > 0 && trees[0] != null) { if (trees.Length == 1) { return(trees[0]); } if (op == LibFive_Operation.Union) { return(LFMath.Union(trees)); } else if (op == LibFive_Operation.Intersection) { return(LFMath.Intersection(trees)); } else if (op == LibFive_Operation.Difference) { return(LFMath.Difference(trees)); } else if (op == LibFive_Operation.Blend) { return(LFMath.Blend(0.1f, trees)); } } return(tree); }
public LFTree Evaluate() { UnityEngine.Profiling.Profiler.BeginSample("Evaluate LibFive Tree", this); using (LFContext.Active = new Context()) { if (op > 0 && (int)op < 100) { tree = evaluateNonary(op); } else if ((int)op < 200 && transform.childCount > 0) { var childShape = transform.GetChild(0).GetComponent <LFShape>(); if (childShape != null && childShape.isActiveAndEnabled) { tree = evaluateUnary(op, childShape.Evaluate()); } } else { var trees = new List <LFTree>(transform.childCount); for (var i = 0; i < transform.childCount; ++i) { var childShape = transform.GetChild(i).GetComponent <LFShape>(); if (childShape != null && childShape.isActiveAndEnabled) { trees.Add(childShape.Evaluate()); } } tree = evaluateNnary(op, trees.ToArray()); } localTransformHash = computeLocalTransformHash(); if (isRootNode && tree != null) { tree = LFMath.Transform(tree, transform.localToWorldMatrix); } else { tree = LFMath.Transform(tree, transform.parent.worldToLocalMatrix * transform.localToWorldMatrix); } LFContext.Active.RemoveTreeFromContext(tree); // (This prevents this node's tree from being disposed of.) } UnityEngine.Profiling.Profiler.EndSample(); return(tree); }
void GenerateMesh(Mesh meshToFill, bool sharpEdges = true) { using (LFContext.Active = new Context()) { float innerRadius = 0.6f + (Mathf.Sin(Time.time) * 0.05f); LFTree cylinder = LFMath.Cylinder(innerRadius, 2f, Vector3.back); LFTree toRender = LFMath.Difference( LFMath.Sphere(1f), cylinder, LFMath.ReflectXZ(cylinder), LFMath.ReflectYZ(cylinder)); toRender.RenderMesh(meshToFill, new Bounds(Vector3.zero, Vector3.one * 3.1f), resolution, 20f); if (sharpEdges) { meshToFill.RecalculateNormals(25f); } } }
LFTree evaluateNonary(LibFive_Operation op) { if (op == LibFive_Operation.Circle) { return(LFMath.Circle(0.5f)); } else if (op == LibFive_Operation.Sphere) { return(LFMath.Sphere(0.5f)); } else if (op == LibFive_Operation.Box) { return(LFMath.Box(-Vector3.one * 0.5f, Vector3.one * 0.5f)); } else if (op == LibFive_Operation.Cylinder) { return(LFMath.Cylinder(0.5f, 1f, Vector3.back * 0.5f)); } return(tree); }
LFTree evaluateUnary(LibFive_Operation op, LFTree tree) { if (tree != null) { if (op == LibFive_Operation.Transform) { return(tree); } else if (op == LibFive_Operation.Inverse) { return(-tree); } else if (op == LibFive_Operation.Mirror) { return(LFMath.SymmetricX(tree)); } else if (op == LibFive_Operation.Shell) { return(LFMath.Shell(tree, 0.025f)); } } return(this.tree); }