diff --git a/5DPlannerTask.xcodeproj/project.pbxproj b/5DPlannerTask.xcodeproj/project.pbxproj index 6af07e8..10a8e02 100644 --- a/5DPlannerTask.xcodeproj/project.pbxproj +++ b/5DPlannerTask.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + A31CA1761EC73EAE00023460 /* laminate_1_2.jpg in Resources */ = {isa = PBXBuildFile; fileRef = A31CA1731EC73EAE00023460 /* laminate_1_2.jpg */; }; + A31CA1771EC73EAE00023460 /* path_6.jpg in Resources */ = {isa = PBXBuildFile; fileRef = A31CA1741EC73EAE00023460 /* path_6.jpg */; }; + A31CA1781EC73EAE00023460 /* wallp_0.jpg in Resources */ = {isa = PBXBuildFile; fileRef = A31CA1751EC73EAE00023460 /* wallp_0.jpg */; }; + A31CA17B1EC73FCB00023460 /* Other.swift in Sources */ = {isa = PBXBuildFile; fileRef = A31CA17A1EC73FCB00023460 /* Other.swift */; }; A36A95601E841AA000BDE440 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36A955F1E841AA000BDE440 /* AppDelegate.swift */; }; A36A95621E841AA000BDE440 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36A95611E841AA000BDE440 /* ViewController.swift */; }; A36A95651E841AA000BDE440 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A36A95631E841AA000BDE440 /* Main.storyboard */; }; @@ -16,7 +20,7 @@ A36A95861E84397900BDE440 /* JSONData.json in Resources */ = {isa = PBXBuildFile; fileRef = A36A95851E84397900BDE440 /* JSONData.json */; }; A36A95B61E84412600BDE440 /* CustomScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36A95B51E84412600BDE440 /* CustomScene.swift */; }; A3D85B8E1E9E37070037CDF0 /* Material.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D85B8D1E9E37070037CDF0 /* Material.swift */; }; - A3D85B901E9E3D530037CDF0 /* TheWall.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D85B8F1E9E3D530037CDF0 /* TheWall.swift */; }; + A3D85B901E9E3D530037CDF0 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D85B8F1E9E3D530037CDF0 /* Node.swift */; }; A3D85B921E9E3DCB0037CDF0 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D85B911E9E3DCB0037CDF0 /* Item.swift */; }; A3D85B981E9E67FC0037CDF0 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D85B971E9E67FC0037CDF0 /* JSON.swift */; }; /* End PBXBuildFile section */ @@ -32,6 +36,10 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + A31CA1731EC73EAE00023460 /* laminate_1_2.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = laminate_1_2.jpg; sourceTree = ""; }; + A31CA1741EC73EAE00023460 /* path_6.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = path_6.jpg; sourceTree = ""; }; + A31CA1751EC73EAE00023460 /* wallp_0.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = wallp_0.jpg; sourceTree = ""; }; + A31CA17A1EC73FCB00023460 /* Other.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Other.swift; sourceTree = ""; }; A36A955C1E841AA000BDE440 /* 5DPlannerTask.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 5DPlannerTask.app; sourceTree = BUILT_PRODUCTS_DIR; }; A36A955F1E841AA000BDE440 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A36A95611E841AA000BDE440 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -45,7 +53,7 @@ A36A95851E84397900BDE440 /* JSONData.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = JSONData.json; sourceTree = ""; }; A36A95B51E84412600BDE440 /* CustomScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomScene.swift; sourceTree = ""; }; A3D85B8D1E9E37070037CDF0 /* Material.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Material.swift; path = 5DPlannerTask/Models/Material.swift; sourceTree = SOURCE_ROOT; }; - A3D85B8F1E9E3D530037CDF0 /* TheWall.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TheWall.swift; path = 5DPlannerTask/Models/TheWall.swift; sourceTree = SOURCE_ROOT; }; + A3D85B8F1E9E3D530037CDF0 /* Node.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Node.swift; path = 5DPlannerTask/Models/Node.swift; sourceTree = SOURCE_ROOT; }; A3D85B911E9E3DCB0037CDF0 /* Item.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Item.swift; path = 5DPlannerTask/Models/Item.swift; sourceTree = SOURCE_ROOT; }; A3D85B971E9E67FC0037CDF0 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JSON.swift; path = 5DPlannerTask/Models/JSON.swift; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ @@ -68,12 +76,30 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + A31CA1721EC73EAE00023460 /* Images */ = { + isa = PBXGroup; + children = ( + A31CA1731EC73EAE00023460 /* laminate_1_2.jpg */, + A31CA1741EC73EAE00023460 /* path_6.jpg */, + A31CA1751EC73EAE00023460 /* wallp_0.jpg */, + ); + path = Images; + sourceTree = ""; + }; + A31CA1791EC73FAD00023460 /* Other */ = { + isa = PBXGroup; + children = ( + A31CA17A1EC73FCB00023460 /* Other.swift */, + ); + path = Other; + sourceTree = ""; + }; A36279001E9B1191004E06D6 /* Models */ = { isa = PBXGroup; children = ( A3D85B971E9E67FC0037CDF0 /* JSON.swift */, A3D85B8D1E9E37070037CDF0 /* Material.swift */, - A3D85B8F1E9E3D530037CDF0 /* TheWall.swift */, + A3D85B8F1E9E3D530037CDF0 /* Node.swift */, A3D85B911E9E3DCB0037CDF0 /* Item.swift */, ); name = Models; @@ -101,6 +127,7 @@ A36A955E1E841AA000BDE440 /* 5DPlannerTask */ = { isa = PBXGroup; children = ( + A31CA1721EC73EAE00023460 /* Images */, A36279001E9B1191004E06D6 /* Models */, A36A955F1E841AA000BDE440 /* AppDelegate.swift */, A36A95851E84397900BDE440 /* JSONData.json */, @@ -110,6 +137,7 @@ A36A95661E841AA000BDE440 /* Assets.xcassets */, A36A95681E841AA000BDE440 /* LaunchScreen.storyboard */, A36A956B1E841AA000BDE440 /* Info.plist */, + A31CA1791EC73FAD00023460 /* Other */, ); path = 5DPlannerTask; sourceTree = ""; @@ -206,8 +234,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A31CA1761EC73EAE00023460 /* laminate_1_2.jpg in Resources */, A36A956A1E841AA000BDE440 /* LaunchScreen.storyboard in Resources */, + A31CA1781EC73EAE00023460 /* wallp_0.jpg in Resources */, A36A95861E84397900BDE440 /* JSONData.json in Resources */, + A31CA1771EC73EAE00023460 /* path_6.jpg in Resources */, A36A95671E841AA000BDE440 /* Assets.xcassets in Resources */, A36A95651E841AA000BDE440 /* Main.storyboard in Resources */, ); @@ -227,7 +258,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - A3D85B901E9E3D530037CDF0 /* TheWall.swift in Sources */, + A31CA17B1EC73FCB00023460 /* Other.swift in Sources */, + A3D85B901E9E3D530037CDF0 /* Node.swift in Sources */, A36A95621E841AA000BDE440 /* ViewController.swift in Sources */, A3D85B981E9E67FC0037CDF0 /* JSON.swift in Sources */, A36A95601E841AA000BDE440 /* AppDelegate.swift in Sources */, diff --git a/5DPlannerTask/CustomScene.swift b/5DPlannerTask/CustomScene.swift index 8189b57..54a155f 100644 --- a/5DPlannerTask/CustomScene.swift +++ b/5DPlannerTask/CustomScene.swift @@ -15,56 +15,31 @@ class CustomScene: SCNScene { super.init() //let scene = SCNScene(named: "sphere.obj")! //let scnView = self as! SCNView - addCamera() - addLights() - addSphere() -// let background = UIImage(named: "IBLBlurred.png") -// scene.background.contents = background + setupScene() } required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) fatalError("init(coder:) has not been implemented") } - func addObjects() { - // retrieve the ship node - //let ship = self.rootNode.childNode(withName: "ship", recursively: true)! - } - - func addSphere() { - let sphereGeometry = SCNSphere(radius: 1.0) - let sphereNode = SCNNode(geometry: sphereGeometry) - sphereGeometry.firstMaterial?.diffuse.contents = UIColor.red - self.rootNode.addChildNode(sphereNode) - } - - func addCamera() { - // create and add a camera to the scene - let cameraNode = SCNNode() - cameraNode.camera = SCNCamera() - self.rootNode.addChildNode(cameraNode) + func setupScene() { + let omniLight = LightNode(type: .omni) + omniLight.position = SCNVector3(x: 0, y: 10, z: 10) + self.rootNode.addChildNode(omniLight) - // place the camera - cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) - } - - func addLights() { - // create and add a light to the scene - let lightNode = SCNNode() - lightNode.light = SCNLight() - lightNode.light!.type = .omni - lightNode.position = SCNVector3(x: 0, y: 10, z: 10) - self.rootNode.addChildNode(lightNode) + let ambientLight = LightNode(type: .ambient) + ambientLight.color = UIColor.darkGray + self.rootNode.addChildNode(ambientLight) - // create and add an ambient light to the scene - let ambientLightNode = SCNNode() - ambientLightNode.light = SCNLight() - ambientLightNode.light!.type = .ambient - ambientLightNode.light!.color = UIColor.darkGray - self.rootNode.addChildNode(ambientLightNode) + let camera = CameraNode() + camera.position = SCNVector3(x: 0, y: 0, z: 15) + self.rootNode.addChildNode(camera) + + setupEnviromentLights() } - func addEnviromentLights() { + private func setupEnviromentLights() { let environment = UIImage(named: "IBL.png") self.lightingEnvironment.contents = environment self.lightingEnvironment.intensity = 2.0 diff --git a/5DPlannerTask/Images/laminate_1_2.jpg b/5DPlannerTask/Images/laminate_1_2.jpg new file mode 100644 index 0000000..a2161a8 Binary files /dev/null and b/5DPlannerTask/Images/laminate_1_2.jpg differ diff --git a/5DPlannerTask/Images/path_6.jpg b/5DPlannerTask/Images/path_6.jpg new file mode 100644 index 0000000..e20394d Binary files /dev/null and b/5DPlannerTask/Images/path_6.jpg differ diff --git a/5DPlannerTask/Images/wallp_0.jpg b/5DPlannerTask/Images/wallp_0.jpg new file mode 100644 index 0000000..bb4e064 Binary files /dev/null and b/5DPlannerTask/Images/wallp_0.jpg differ diff --git a/5DPlannerTask/JSONData.json b/5DPlannerTask/JSONData.json index 80300e7..a954cf7 100644 --- a/5DPlannerTask/JSONData.json +++ b/5DPlannerTask/JSONData.json @@ -1 +1 @@ -{"hash":"63a807e2624cec7a705c46b74fcbe64b","readOnly":0,"name":"New project","s":0,"data":{"className":"Project","version":2,"width":8000,"height":8000,"ss":[],"sscounter":0,"s":0,"currentFloor":0,"autoinc":14,"ground":{"texture":"bg_1_fill.png","color":"#fff"},"v":1,"readOnly":0,"items":[{"className":"Floor","name":"First floor","h":275,"puid":"p1","items":[{"className":"Room","x":3750,"y":3750,"z":0,"sX":204,"sY":204,"rtype":0,"h":270,"materials":{"floor":{"texture":"laminate_1_2","color":"#FFFFFF","scale":1,"rotate":0},"ceil":{"texture":"linen_1_4","color":"#FFFFFF","scale":1,"rotate":0},"indoor":{"texture":"wallp_0","color":"#FFFFFF","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#FFFFFF","scale":1,"rotate":0}},"rhidden":false,"fhidden":false,"puid":"p2","items":[{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p3","items":[{"className":"Point","x":0,"y":0,"puid":"p4"},{"className":"Point","x":510,"y":0,"puid":"p5"}]},{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p6","items":[{"className":"Point","x":510,"y":0,"puid":"p7"},{"className":"Point","x":510,"y":510,"puid":"p8"}]},{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p9","items":[{"className":"Point","x":510,"y":510,"puid":"p10"},{"className":"Point","x":0,"y":510,"puid":"p11"}]},{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p12","items":[{"className":"Point","x":0,"y":510,"puid":"p13"},{"className":"Point","x":0,"y":0,"puid":"p14"}]}]}]}]}} +{"hash":"63a807e2624cec7a705c46b74fcbe64b","readOnly":0,"name":"New project","s":0,"data":{"className":"Project","version":2,"width":8000,"height":8000,"ss":[],"sscounter":0,"s":0,"currentFloor":0,"autoinc":14,"ground":{"texture":"path_6.jpg","color":"#767e4c"},"v":1,"readOnly":0,"items":[{"className":"Floor","name":"First floor","h":275,"puid":"p1","items":[{"className":"Room","x":3750,"y":3750,"z":0,"sX":204,"sY":204,"rtype":0,"h":270,"materials":{"floor":{"texture":"laminate_1_2","color":"#FFFFFF","scale":1,"rotate":0},"ceil":{"texture":"linen_1_4","color":"#FFFFFF","scale":1,"rotate":0},"indoor":{"texture":"wallp_0","color":"#FFFFFF","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#FFFFFF","scale":1,"rotate":0}},"rhidden":false,"fhidden":false,"puid":"p2","items":[{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p3","items":[{"className":"Point","x":0,"y":0,"puid":"p4"},{"className":"Point","x":510,"y":0,"puid":"p5"}]},{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p6","items":[{"className":"Point","x":510,"y":0,"puid":"p7"},{"className":"Point","x":510,"y":510,"puid":"p8"}]},{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p9","items":[{"className":"Point","x":510,"y":510,"puid":"p10"},{"className":"Point","x":0,"y":510,"puid":"p11"}]},{"className":"Wall","hidden":false,"w":10,"materials":{"indoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0},"outdoor":{"texture":"wallp_0","color":"#ffffff","scale":1,"rotate":0}},"puid":"p12","items":[{"className":"Point","x":0,"y":510,"puid":"p13"},{"className":"Point","x":0,"y":0,"puid":"p14"}]}]}]}]}} diff --git a/5DPlannerTask/Models/Item.swift b/5DPlannerTask/Models/Item.swift index 5ebadd3..c1a2fa6 100644 --- a/5DPlannerTask/Models/Item.swift +++ b/5DPlannerTask/Models/Item.swift @@ -7,7 +7,6 @@ // import UIKit -import SceneKit class Item: DataExtractProtocol { var items: [[String: AnyObject]]? @@ -95,6 +94,7 @@ class Room: Floor { class Wall: Room { var w: CGFloat? //width + var points: [Point] = [] override func extract(_ item: [String : AnyObject]) { if let value = extractData(input: item, using: "w") as? CGFloat { diff --git a/5DPlannerTask/Models/JSON.swift b/5DPlannerTask/Models/JSON.swift index 2f46ddc..fe2d36f 100644 --- a/5DPlannerTask/Models/JSON.swift +++ b/5DPlannerTask/Models/JSON.swift @@ -9,6 +9,7 @@ import UIKit class JSON: NSObject, DataExtractProtocol { + var projectName: String? var data: [String: AnyObject]? @@ -50,8 +51,6 @@ class JSONData { } } - - // func extractItems(input: [String: AnyObject]) { // if let items = extractData(input: input, using: "items") as? [AnyObject] { // for item in items { diff --git a/5DPlannerTask/Models/Node.swift b/5DPlannerTask/Models/Node.swift new file mode 100644 index 0000000..d156227 --- /dev/null +++ b/5DPlannerTask/Models/Node.swift @@ -0,0 +1,106 @@ +// +// TheWall.swift +// 5DPlannerTask +// +// Created by Darius Miliauskas on 12/04/2017. +// Copyright © 2017 Darius Miliauskas. All rights reserved. +// + +import UIKit +import SceneKit + +// MARK: Scene Basic Nodes + +class CameraNode: SCNNode { + convenience override init() { + self.init() + self.camera = SCNCamera() + } +} + +class LightNode: SCNNode { + internal var theLight = SCNLight() + var color: UIColor? + + convenience init(type: SCNLight.LightType) { + self.init() + theLight.type = type + self.light = theLight + + if theLight.type == .omni { + self.position = SCNVector3(x: 0, y: 10, z: 10) + } + + if let theColor = color, theLight.type == .ambient { + theLight.color = theColor + } + } +} + +// MARK: Scene Object Nodes + +class WallNode: SCNNode { + var width: CGFloat = 0.0 + var height: CGFloat = 0.0 + var length: CGFloat = 0.0 + var material: Material? + + convenience override init() { + self.init() + let geometry = SCNBox(width: width, height: height, length: length, chamferRadius: 0) + self.geometry = geometry + self.position = SCNVector3(x: 0, y: 0, z: 0) + if let imageName = material?.imageName, let color = material?.color { + geometry.firstMaterial?.diffuse.contents = color + geometry.firstMaterial?.diffuse.contents = UIImage(named: imageName) + } + } + + func setup(wall: Wall) { +// self.init() + guard let point1 = wall.points.first, let point2 = wall.points.last else { + return + } + + guard let x1 = point1.pointX, let y1 = point1.pointY else { + return + } + + guard let x2 = point2.pointX, let y2 = point2.pointY else { + return + } + + self.position = SCNVector3(x: Float(x1), y: Float(y1), z: 0) + let height = CGFloat(sqrt(Double(x1*x2 + y1*y2))) + + if let width = wall.w, let length = wall.h { + self.length = length + + if x1 == x2 { + self.width = width + self.height = height + } + + if y1 == y2 { + self.width = height + self.height = width + } + } + } +} + +class SphereNode: SCNNode { + var radius: CGFloat? = 1.0 + var color: UIColor? + var material: Material? + + convenience override init() { + self.init() + if let radius = radius, let imageName = material?.imageName, let color = material?.color { + let sphereGeometry = SCNSphere(radius: radius) + sphereGeometry.firstMaterial?.diffuse.contents = color + sphereGeometry.firstMaterial?.diffuse.contents = UIImage(named: imageName) + } + } +} + diff --git a/5DPlannerTask/Models/TheWall.swift b/5DPlannerTask/Models/TheWall.swift deleted file mode 100644 index 15e847f..0000000 --- a/5DPlannerTask/Models/TheWall.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// TheWall.swift -// 5DPlannerTask -// -// Created by Darius Miliauskas on 12/04/2017. -// Copyright © 2017 Darius Miliauskas. All rights reserved. -// - -import UIKit - -class TheWall: NSObject { - - - - -} - - diff --git a/5DPlannerTask/Other/Other.swift b/5DPlannerTask/Other/Other.swift new file mode 100644 index 0000000..07309da --- /dev/null +++ b/5DPlannerTask/Other/Other.swift @@ -0,0 +1,101 @@ +// +// Other.swift +// 5DPlannerTask +// +// Created by Darius Miliauskas on 13/05/2017. +// Copyright © 2017 Darius Miliauskas. All rights reserved. +// + +//https://medium.com/@avihay/amazing-physically-based-rendering-using-the-new-ios-10-scenekit-2489e43f7021#.vdapbrnj7 +//https://www.weheartswift.com/introduction-scenekit-part-1/ + +import Foundation + +enum Element: String { + case Room = "Room" + case Floor = "Floor" + case Wall = "Wall" + case Point = "Point" + + var parameters: [String] { + switch self { + case .Room: + return ["x", "y", "z", "h"] + case .Floor: + return ["h"] + case .Wall: + return ["w"] + case .Point: + return ["x", "y"] + } + } +} + +//@objc protocol ItemsExtractProtocol: DataExtractProtocol { +// optional func extractItems(input: [String : AnyObject]) -> [AnyObject] +//} +// +//extension ItemsExtractProtocol { +// func extractItems(input: [String : AnyObject]) -> [AnyObject] { +// if let items = extractData(input: input, using: "items") as? [AnyObject] { +// return items +// // for item in items { +// // if let theItem = item as? [String : AnyObject] { +// // +// // } +// // } +// } +// return [] +// } +//} + +class Other { + +// MARK: Extracting Data + +/* + + //Extracting the properties like className, h etc. + func extractItemProperties(_ input: [String: AnyObject]) { + if let className = extractData(input: input, using: "className") as? String { + print(className) + if let type = Element(rawValue: className) { + for parameter in type.parameters { + if let value = extractData(input: input, using: parameter) as? NSNumber { + print(parameter+": \(value)") + } + } + } + + //check if materials can be extracted since not all objects have materials + if className == "Room" || className == "Wall" { + self.extractItemMaterials(input) + } + + if className != "Point" { + extractItems(input: input) + } + } + } + + func extractItemMaterials(_ input: [String: AnyObject]) { + if let materials = extractData(input: input, using: "materials") as? [String:AnyObject] { + for side in ["indoor", "outdoor", "floor", "ceil"] { + if let feature = extractData(input: materials, using: side) as? [String:AnyObject] { + extractMaterial(feature) + } + } + } + } + + func extractItems(input: [String: AnyObject]) { + if let items = extractData(input: input, using: "items") as? [AnyObject] { + for item in items { + if let theItem = item as? [String : AnyObject] { + extractItemProperties(theItem) + // extractItems(input: theItem) + } + } + } + }*/ +} diff --git a/5DPlannerTask/ViewController.swift b/5DPlannerTask/ViewController.swift index 49df8be..90c9a1f 100644 --- a/5DPlannerTask/ViewController.swift +++ b/5DPlannerTask/ViewController.swift @@ -9,8 +9,7 @@ import UIKit import SceneKit -//https://medium.com/@avihay/amazing-physically-based-rendering-using-the-new-ios-10-scenekit-2489e43f7021#.vdapbrnj7 -//https://www.weheartswift.com/introduction-scenekit-part-1/ +//https://planner5d.com/editor/?key=63a807e2624cec7a705c46b74fcbe64b class ViewController: UIViewController { @@ -29,11 +28,10 @@ class ViewController: UIViewController { func render() { sceneView.scene = CustomScene() - sceneView.backgroundColor = UIColor.black + //sceneView.backgroundColor = UIColor.black sceneView.allowsCameraControl = true } - func run() { //let data: [String : AnyObject]=[:] let input = JSONData.parseJSON(fileName: "JSONData") @@ -50,97 +48,35 @@ class ViewController: UIViewController { for item in room.items! { let wall = Wall(data: item) wall.extract(item) + + for item in wall.items! { + let point = Point(data: item) + point.extract(item) + wall.points.append(point) + } + + let wallNode = WallNode() + wallNode.setup(wall: wall) +// node.addChildNode(wallNode) } } - // let wallGeometry = SCNBox(width: point.w, height: point.h, length: point.x, chamferRadius: 0.0) } - - - //print(parseJSON(fileName: "JSONData")) // let json = JSON() - //json.extract(fileName: "JSONData") + //json.extract(fileName: "JSONData") + - //JSON(input: input) -// let project = Project(json: JSON(fileName: "JSONData")) - } - - // MARK: Extracting Data - - - -/* - - //Extracting the properties like className, h etc. - func extractItemProperties(_ input: [String: AnyObject]) { - if let className = extractData(input: input, using: "className") as? String { - print(className) - if let type = Element(rawValue: className) { - for parameter in type.parameters { - if let value = extractData(input: input, using: parameter) as? NSNumber { - print(parameter+": \(value)") - } - } - } - - //check if materials can be extracted since not all objects have materials - if className == "Room" || className == "Wall" { - self.extractItemMaterials(input) - } - - if className != "Point" { - extractItems(input: input) - } - } + // let project = Project(json: JSON(fileName: "JSONData")) } - - func extractItemMaterials(_ input: [String: AnyObject]) { - if let materials = extractData(input: input, using: "materials") as? [String:AnyObject] { - for side in ["indoor", "outdoor", "floor", "ceil"] { - if let feature = extractData(input: materials, using: side) as? [String:AnyObject] { - extractMaterial(feature) - } - } - } - } - - func extractItems(input: [String: AnyObject]) { - if let items = extractData(input: input, using: "items") as? [AnyObject] { - for item in items { - if let theItem = item as? [String : AnyObject] { - extractItemProperties(theItem) -// extractItems(input: theItem) - } - } - } - }*/ } protocol ExtractProtocol { func extract(_ item: [String : AnyObject]) } -//protocol ItemsExtractProtocol: DataExtractProtocol { -// func extractItems(input: [String : AnyObject]) -> [AnyObject] -//} -// -//extension ItemsExtractProtocol { -// func extractItems(input: [String : AnyObject]) -> [AnyObject] { -// if let items = extractData(input: input, using: "items") as? [AnyObject] { -// return items -// // for item in items { -// // if let theItem = item as? [String : AnyObject] { -// // -// // } -// // } -// } -// return [] -// } -//} - protocol DataExtractProtocol { func extractData(input: [String: AnyObject], using keyword: String) -> AnyObject? } @@ -157,27 +93,3 @@ extension DataExtractProtocol { } } } - - - - - -enum Element: String { - case Room = "Room" - case Floor = "Floor" - case Wall = "Wall" - case Point = "Point" - - var parameters: [String] { - switch self { - case .Room: - return ["x", "y", "z", "h"] - case .Floor: - return ["h"] - case .Wall: - return ["w"] - case .Point: - return ["x", "y"] - } - } -}