Skip to content

Commit

Permalink
Refactor Code Step 1 Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dariukas committed May 13, 2017
1 parent 0b4c8d0 commit 3aaf8e9
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 169 deletions.
40 changes: 36 additions & 4 deletions 5DPlannerTask.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 */
Expand All @@ -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 = "<group>"; };
A31CA1741EC73EAE00023460 /* path_6.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = path_6.jpg; sourceTree = "<group>"; };
A31CA1751EC73EAE00023460 /* wallp_0.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = wallp_0.jpg; sourceTree = "<group>"; };
A31CA17A1EC73FCB00023460 /* Other.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Other.swift; sourceTree = "<group>"; };
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 = "<group>"; };
A36A95611E841AA000BDE440 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand All @@ -45,7 +53,7 @@
A36A95851E84397900BDE440 /* JSONData.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = JSONData.json; sourceTree = "<group>"; };
A36A95B51E84412600BDE440 /* CustomScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomScene.swift; sourceTree = "<group>"; };
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 */
Expand All @@ -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 = "<group>";
};
A31CA1791EC73FAD00023460 /* Other */ = {
isa = PBXGroup;
children = (
A31CA17A1EC73FCB00023460 /* Other.swift */,
);
path = Other;
sourceTree = "<group>";
};
A36279001E9B1191004E06D6 /* Models */ = {
isa = PBXGroup;
children = (
A3D85B971E9E67FC0037CDF0 /* JSON.swift */,
A3D85B8D1E9E37070037CDF0 /* Material.swift */,
A3D85B8F1E9E3D530037CDF0 /* TheWall.swift */,
A3D85B8F1E9E3D530037CDF0 /* Node.swift */,
A3D85B911E9E3DCB0037CDF0 /* Item.swift */,
);
name = Models;
Expand Down Expand Up @@ -101,6 +127,7 @@
A36A955E1E841AA000BDE440 /* 5DPlannerTask */ = {
isa = PBXGroup;
children = (
A31CA1721EC73EAE00023460 /* Images */,
A36279001E9B1191004E06D6 /* Models */,
A36A955F1E841AA000BDE440 /* AppDelegate.swift */,
A36A95851E84397900BDE440 /* JSONData.json */,
Expand All @@ -110,6 +137,7 @@
A36A95661E841AA000BDE440 /* Assets.xcassets */,
A36A95681E841AA000BDE440 /* LaunchScreen.storyboard */,
A36A956B1E841AA000BDE440 /* Info.plist */,
A31CA1791EC73FAD00023460 /* Other */,
);
path = 5DPlannerTask;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand All @@ -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 */,
Expand Down
55 changes: 15 additions & 40 deletions 5DPlannerTask/CustomScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added 5DPlannerTask/Images/laminate_1_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5DPlannerTask/Images/path_6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5DPlannerTask/Images/wallp_0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion 5DPlannerTask/JSONData.json
Original file line number Diff line number Diff line change
@@ -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"}]}]}]}]}}
2 changes: 1 addition & 1 deletion 5DPlannerTask/Models/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import UIKit
import SceneKit

class Item: DataExtractProtocol {
var items: [[String: AnyObject]]?
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions 5DPlannerTask/Models/JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit

class JSON: NSObject, DataExtractProtocol {

var projectName: String?
var data: [String: AnyObject]?

Expand Down Expand Up @@ -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 {
Expand Down
106 changes: 106 additions & 0 deletions 5DPlannerTask/Models/Node.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

18 changes: 0 additions & 18 deletions 5DPlannerTask/Models/TheWall.swift

This file was deleted.

Loading

0 comments on commit 3aaf8e9

Please sign in to comment.