private string GetShapeCode(SDFShape shape, string parentPosition) { Vector3 offset = shape.transform.localPosition; Vector3 up = shape.transform.localRotation * Vector3.up; // Vector3 right = shape.transform.localRotation * Vector3.right; // Vector3 forward = shape.transform.localRotation * Vector3.forward; Vector3 parameters = shape.GetParameters(); switch (shape.shapeType) { case SDFShape.ShapeType.Plane: return("dot(" + parentPosition + " - " + ConstructVariable(offset) + ", " + ConstructVariable(up) + ")"); case SDFShape.ShapeType.FracturedPlane: //return "wsPos.y + (clamp(wsPos.x, 0.0, 2.0) * 0.05 + clamp(wsPos.z + .5, 0.0, 1.0) * .1)"; return("frPlane(wsPos)"); case SDFShape.ShapeType.Sphere: return("length(wsPos) - .5"); case SDFShape.ShapeType.Cube: return("fBox(wsPos," + ConstructVariable(shape.GetParameters()) + ")"); case SDFShape.ShapeType.Cylinder: return("fCylinder(wsPos, " + ConstructVariable(parameters.x) + "," + ConstructVariable(parameters.y) + ")"); } return("0.0"); // Worst case }
private void BuildNodeTree(GameObject go, List <Node> nodeList, int depth) { if (!go.activeInHierarchy) { return; } SDFOperation op = go.GetComponent <SDFOperation>(); SDFShape shape = go.GetComponent <SDFShape>(); Vector3 scale = go.transform.localScale; if (shape) { scale = GetShapeLocalScale(shape); } Node node = new Node(); node.transform = Matrix4x4.TRS(go.transform.localPosition, go.transform.localRotation, scale).inverse; node.type = 0; node.depth = depth; node.domainDistortionType = 0; node.domainDistortion = Vector3.one; node.bias = 1f; if (op) { node.type = 0; node.parameters = (int)op.operationType; node.domainDistortionType = (int)op.distortionType; node.domainDistortion = op.domainRepeat; // For now... node.bias = 1f; } else if (shape) { node.type = 1; node.parameters = (int)shape.shapeType; node.domainDistortion = shape.GetParameters(); node.bias = shape.sdfBias; } nodeList.Add(node); foreach (Transform child in go.transform) { BuildNodeTree(child.gameObject, nodeList, depth + 1); } }