-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4ee9f0
commit b7b0607
Showing
10 changed files
with
708 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Ring.swift | ||
// | ||
// | ||
// Created by Carlyn Maw on 7/25/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct Ring { | ||
public init(count:Int, radius:Int) { | ||
self.count = count | ||
} | ||
let count:Int | ||
let minTranslate = -4.0 | ||
let maxTranslate = 4.0 | ||
let minRadius = 0.8 | ||
let maxRadius = 2.0 | ||
|
||
let tau = Double.pi * 2 | ||
|
||
public func buildStage() -> Canvas3D { | ||
let base_theta = tau/Double(count) | ||
let color = 0.5 | ||
return Canvas3D { | ||
Sphere(radius: 1.0).color(red: 0.18, green: 0.18, blue: 0.18) | ||
for i in 0..<count { | ||
let theta = base_theta * Double(i) | ||
let x = cos(theta) | ||
let y = sin(theta) | ||
|
||
Sphere(radius: 1.0) | ||
.color( | ||
red: color, | ||
green: color, | ||
blue: color | ||
) | ||
//The ranges are all the same in this case. | ||
.translateBy(Vector(x: x, y: y, z: 0.0)) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// SketchPadCLI/testsketch.swift | ||
// | ||
// | ||
// Created by Carlyn Maw on 7/11/25. | ||
// | ||
|
||
import Foundation | ||
import ArgumentParser | ||
import SketchPad | ||
|
||
|
||
extension SketchPadCLI { | ||
struct testsketch:ParsableCommand { | ||
@Flag(name: [.customLong("save"), .customShort("s")], help: "Will save to file called \"testsketch_$TIMESTAMP.usda\" instead of printing to stdout") | ||
var saveToFile = false | ||
|
||
@Option(name: [.customLong("output"), .customShort("o")], help: "Will save to custom path instead of printing to stdout") | ||
var customPath:String? = nil | ||
|
||
@Option(name: [.customLong("count"), .customShort("c")], | ||
help: "Number of spheres to generate in addition to the blue origin sphere. Default is 12") | ||
var count:Int = 18 | ||
|
||
@Option(name: [.customLong("radius"), .customShort("r")], | ||
help: "Number of spheres to generate in addition to the blue origin sphere. Default is 12") | ||
var radius:Int = 12 | ||
|
||
|
||
static var configuration = | ||
CommandConfiguration(abstract: "Generate a USDA file that references sphere_base.usda like previous examples. 12 + blue origin ball is the default count") | ||
|
||
func run() { | ||
let stage = Ring(count:count, radius: 12).buildStage() | ||
let fileBuilder_x3d = X3DFileBuilder()//USDAFileBuilder() | ||
let fileString_x3d:String = fileBuilder_x3d.generateStringForStage(stage: stage) | ||
let fileBuilder_usd = USDAFileBuilder()//USDAFileBuilder() | ||
let fileString_usd:String = fileBuilder_usd.generateStringForStage(stage: stage) | ||
|
||
if saveToFile || customPath != nil { | ||
let timeStamp = FileIO.timeStamp() | ||
let path = customPath ?? "testsketch_\(timeStamp).usda" | ||
saveFile(fileString: fileString_usd, path: path) | ||
let path_x3d = "testsketch_\(timeStamp).x3d" | ||
saveFile(fileString: fileString_x3d, path: path_x3d) | ||
} else { | ||
print(fileString_usd) | ||
print("------------------") | ||
print(fileString_x3d) | ||
} | ||
} | ||
|
||
func saveFile(fileString:String, path:String, ext:String? = nil) { | ||
do { | ||
guard let data:Data = fileString.data(using: .utf8) else { | ||
print("Could not encode string to data") | ||
return | ||
} | ||
var fullPath:String | ||
if let ext { | ||
fullPath = "\(path).\(ext)" | ||
} else { | ||
fullPath = path | ||
} | ||
try FileIO.writeToFile(data: data, filePath: fullPath) | ||
} catch { | ||
print("Could not write data to file: \(error)") | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
213 changes: 213 additions & 0 deletions
213
explorations/Part_18/hello_ring/testsketch_20230725T085314.usda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
#usda 1.0 | ||
( | ||
metersPerUnit = 1 | ||
upAxis = "Y" | ||
defaultPrim = "Sphere_59699" | ||
) | ||
def Xform "Sphere_59699" | ||
{ | ||
def Sphere "sphere_59699" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.18, 0.18, 0.18)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_45170" | ||
{ | ||
double3 xformOp:translate = (1.0, 0.0, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_45170" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_60450" | ||
{ | ||
double3 xformOp:translate = (0.9396926207859084, 0.3420201433256687, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_60450" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_73729" | ||
{ | ||
double3 xformOp:translate = (0.766044443118978, 0.6427876096865393, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_73729" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_98021" | ||
{ | ||
double3 xformOp:translate = (0.5000000000000001, 0.8660254037844386, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_98021" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_14599" | ||
{ | ||
double3 xformOp:translate = (0.17364817766693041, 0.984807753012208, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_14599" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_40284" | ||
{ | ||
double3 xformOp:translate = (-0.1736481776669303, 0.984807753012208, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_40284" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_78825" | ||
{ | ||
double3 xformOp:translate = (-0.49999999999999983, 0.8660254037844387, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_78825" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_73649" | ||
{ | ||
double3 xformOp:translate = (-0.7660444431189779, 0.6427876096865395, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_73649" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_80537" | ||
{ | ||
double3 xformOp:translate = (-0.9396926207859083, 0.3420201433256689, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_80537" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_48934" | ||
{ | ||
double3 xformOp:translate = (-1.0, 1.2246467991473532e-16, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_48934" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_38944" | ||
{ | ||
double3 xformOp:translate = (-0.9396926207859084, -0.34202014332566866, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_38944" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_96720" | ||
{ | ||
double3 xformOp:translate = (-0.766044443118978, -0.6427876096865393, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_96720" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_71870" | ||
{ | ||
double3 xformOp:translate = (-0.5000000000000004, -0.8660254037844384, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_71870" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_85226" | ||
{ | ||
double3 xformOp:translate = (-0.17364817766693033, -0.984807753012208, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_85226" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_13040" | ||
{ | ||
double3 xformOp:translate = (0.17364817766692997, -0.9848077530122081, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_13040" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_30100" | ||
{ | ||
double3 xformOp:translate = (0.5000000000000001, -0.8660254037844386, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_30100" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_72205" | ||
{ | ||
double3 xformOp:translate = (0.7660444431189778, -0.6427876096865396, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_72205" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} | ||
def Xform "Sphere_17832" | ||
{ | ||
double3 xformOp:translate = (0.9396926207859081, -0.34202014332566943, 0.0) | ||
uniform token[] xformOpOrder = ["xformOp:translate"] | ||
def Sphere "sphere_17832" | ||
{ | ||
float3[] extent = [(-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)] | ||
color3f[] primvars:displayColor = [(0.5, 0.5, 0.5)] | ||
double radius = 1.0 | ||
} | ||
} |
Oops, something went wrong.