protected override SDFNode GenerateNode() { var intersection = _cachedNode as Intersection; var union = _cachedNode as Union; var smoothUnion = _cachedNode as UnionSmooth; switch (Type) { case BinaryType.Intersection: if (intersection == null) { _cachedNode = intersection = new Intersection(); } break; case BinaryType.Union: if (union == null) { _cachedNode = union = new Union(); } break; case BinaryType.SmoothUnion: if (smoothUnion == null) { _cachedNode = smoothUnion = new UnionSmooth(); } smoothUnion.Operation.K = K; break; } return(_cachedNode); }
private SDFNode GenerateNode() { //Shapes var sphere = _cachedNode as Sphere; var box = _cachedNode as Box; //Binaries var intersection = _cachedNode as Intersection; var union = _cachedNode as Union; var smoothUnion = _cachedNode as UnionSmooth; //Unaries var inverse = _cachedNode as Inverse; var offset = _cachedNode as Offset; //Domains var modSimple = _cachedNode as ModSimple; switch (Type) { //Shapes case NodeType.Sphere: if (sphere == null) { _cachedNode = sphere = new Sphere(); } sphere.Center = transform.position; sphere.Radius = transform.lossyScale.x * 0.5f; break; case NodeType.Box: if (box == null) { _cachedNode = box = new Box(); } box.ToLocalSpace = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one).inverse; box.Extents = transform.lossyScale * 0.5f; break; //Binaries case NodeType.Intersection: if (intersection == null) { _cachedNode = intersection = new Intersection(); } break; case NodeType.Union: if (union == null) { _cachedNode = union = new Union(); } break; case NodeType.SmoothUnion: if (smoothUnion == null) { _cachedNode = smoothUnion = new UnionSmooth(); } smoothUnion.K = K; break; //Unaries case NodeType.Inverse: if (inverse == null) { _cachedNode = inverse = new Inverse(); } break; case NodeType.Offset: if (offset == null) { _cachedNode = offset = new Offset(); } offset.Value = Offset; break; //Domains case NodeType.ModSimple: if (modSimple == null) { _cachedNode = modSimple = new ModSimple(); } modSimple.CellSize = CellSize; modSimple.ModX = X; modSimple.ModY = Y; modSimple.ModZ = Z; break; } return(_cachedNode); }