summaryrefslogtreecommitdiff
path: root/ShedCalc/RenderView.swift
diff options
context:
space:
mode:
authorArturs Artamonovs <arturs.artamonovs@protonmail.com>2026-08-07 02:01:40 +0100
committerArturs Artamonovs <arturs.artamonovs@protonmail.com>2026-08-07 02:01:40 +0100
commit91d0042017e6c46f2c9f5d42d438836efa6d53e4 (patch)
treeaf8c2dbad8ea148e882136843634ff53c42dd20b /ShedCalc/RenderView.swift
parentdabeb1603cf146aa671dddf949788b514b983b76 (diff)
downloadShedCalc-91d0042017e6c46f2c9f5d42d438836efa6d53e4.tar.gz
ShedCalc-91d0042017e6c46f2c9f5d42d438836efa6d53e4.zip
Added 3 views. Added basic beam drawing and basic calculations for width and length + beam drawing
Diffstat (limited to 'ShedCalc/RenderView.swift')
-rw-r--r--ShedCalc/RenderView.swift70
1 files changed, 70 insertions, 0 deletions
diff --git a/ShedCalc/RenderView.swift b/ShedCalc/RenderView.swift
new file mode 100644
index 0000000..a143e99
--- /dev/null
+++ b/ShedCalc/RenderView.swift
@@ -0,0 +1,70 @@
+//
+// RenderView.swift
+// ShedCalc
+//
+// Created by Jacky Jack on 28/07/2026.
+//
+import SwiftUI
+import RealityKit
+
+struct RenderView: View {
+ private let renderController = RenderController()
+ @Environment(ParamModel.self) var paramModel
+ @StateObject private var viewModel = RenderModel()
+ @State private var lastDrag: CGSize = .zero
+
+ var body: some View {
+ VStack(spacing: 0) {
+ RealityView { content in
+ //add objects to scence
+ let scene = renderController.createScene(dimensions: [0,0,0], rotation: [0,0])
+ content.add(scene)
+
+ //add lights to scene
+
+ //create camera view
+ let camera = renderController.createCamera()
+ content.add(camera)
+
+ //draw beams
+ //let beam = renderController.createBeam2x4(position: [0,0,0], height: 2.4, lookFrom: camera.position, id: "beam0")
+ //content.addChild(beam)
+
+ //draw all beams
+ let beamData = renderController.generateShedWall(position: [0,0,0], height: paramModel.height, widthNum: paramModel.widthBeamNum(), lengthNum: paramModel.lengthBeamNum(), spaceBeem: paramModel.beamSpace)
+ //content.add(beams)
+ let beams = renderController.createBeams(beamData)
+ beams.forEach { scene.addChild($0) }
+
+ } update: { content in
+ // Update box geometry directly in the scene
+ if let scene = content.entities.first(where: { $0.name == "scene" }),
+ let box = scene.findEntity(named: "box") as? ModelEntity {
+ box.model?.mesh = .generateBox(size: paramModel.dimensions(), cornerRadius: 0.02)
+ }
+ // Update scene rotation directly
+ if let scene = content.entities.first(where: { $0.name == "scene" }) {
+ let xRot = simd_quatf(angle: viewModel.rotationX, axis: [1, 0, 0])
+ let yRot = simd_quatf(angle: viewModel.rotationY, axis: [0, 1, 0])
+ scene.transform.rotation = yRot * xRot
+ }
+ }.gesture(
+ DragGesture()
+ .onChanged { value in
+ let result = renderController.handleDragGesture(
+ value,
+ lastDrag: lastDrag,
+ currentRotation: [viewModel.rotationX, viewModel.rotationY]
+ )
+ viewModel.rotationX = result.rotation.x
+ viewModel.rotationY = result.rotation.y
+ lastDrag = result.drag
+ }
+ .onEnded { _ in
+ lastDrag = .zero
+ }
+ )
+ }
+ .frame(minWidth: 500, minHeight: 500)
+ }
+}