Skip to content

Commit

Permalink
scene serialization stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Carroll committed Nov 2, 2018
1 parent a92012c commit 1423926
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 78 deletions.
16 changes: 4 additions & 12 deletions SJU-Rock-Wall/SJU-Rock-Wall.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
3205083E215E9794000B63AF /* portland-concrete-effect-vinyl-flooring-grey.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 3205083D215E9794000B63AF /* portland-concrete-effect-vinyl-flooring-grey.jpg */; };
32050840215E9799000B63AF /* iS_makeitdouble.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 3205083F215E9799000B63AF /* iS_makeitdouble.jpg */; };
32261168215C54880041EE81 /* rockWall.scn in Resources */ = {isa = PBXBuildFile; fileRef = 32261167215C54880041EE81 /* rockWall.scn */; };
32F43FF721837C2500591B41 /* SceneSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F43FF621837C2500591B41 /* SceneSerializer.swift */; };
32F43FF921837D5D00591B41 /* SerialTest.scn in Resources */ = {isa = PBXBuildFile; fileRef = 32F43FF821837D5D00591B41 /* SerialTest.scn */; };
660F298A218D0C5E00038BE0 /* rockWall-2.scn in Resources */ = {isa = PBXBuildFile; fileRef = 660F2989218D0C5E00038BE0 /* rockWall-2.scn */; };
662C072F2166E45600559225 /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 662C072E2166E45600559225 /* HomeViewController.swift */; };
666396032162FB2300474CBF /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 666396022162FB2300474CBF /* LoginViewController.swift */; };
66A35AF0218292FB008F2B8C /* RoutesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66A35AEF218292FB008F2B8C /* RoutesTableViewController.swift */; };
Expand Down Expand Up @@ -49,11 +47,9 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
3205083D215E9794000B63AF /* portland-concrete-effect-vinyl-flooring-grey.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = "portland-concrete-effect-vinyl-flooring-grey.jpg"; path = "Assets.xcassets/portland-concrete-effect-vinyl-flooring-grey.jpg"; sourceTree = "<group>"; };
3205083F215E9799000B63AF /* iS_makeitdouble.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = iS_makeitdouble.jpg; path = Assets.xcassets/iS_makeitdouble.jpg; sourceTree = "<group>"; };
32261167215C54880041EE81 /* rockWall.scn */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; name = rockWall.scn; path = Assets.xcassets/rockWall.scn; sourceTree = "<group>"; };
32F43FF621837C2500591B41 /* SceneSerializer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneSerializer.swift; sourceTree = "<group>"; };
32F43FF821837D5D00591B41 /* SerialTest.scn */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = SerialTest.scn; sourceTree = "<group>"; };
660F2989218D0C5E00038BE0 /* rockWall-2.scn */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; name = "rockWall-2.scn"; path = "Assets.xcassets/rockWall-2.scn"; sourceTree = "<group>"; };
662C072E2166E45600559225 /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
666396022162FB2300474CBF /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
66A35AEF218292FB008F2B8C /* RoutesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoutesTableViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -127,6 +123,7 @@
FE7CD1502159ACB700777664 /* SJU-Rock-Wall */ = {
isa = PBXGroup;
children = (
660F2989218D0C5E00038BE0 /* rockWall-2.scn */,
FE7CD1512159ACB700777664 /* AppDelegate.swift */,
FE7CD1552159ACB700777664 /* GameViewController.swift */,
FE7CD1572159ACB700777664 /* Main.storyboard */,
Expand All @@ -140,10 +137,7 @@
9B28463021671CA60009ACD4 /* CreateRouteViewController.swift */,
32F43FF621837C2500591B41 /* SceneSerializer.swift */,
FE7CD15A2159ACB800777664 /* Assets.xcassets */,
32261167215C54880041EE81 /* rockWall.scn */,
32F43FF821837D5D00591B41 /* SerialTest.scn */,
3205083D215E9794000B63AF /* portland-concrete-effect-vinyl-flooring-grey.jpg */,
3205083F215E9799000B63AF /* iS_makeitdouble.jpg */,
FE7CD15C2159ACB800777664 /* LaunchScreen.storyboard */,
FE7CD15F2159ACB800777664 /* Info.plist */,
FE7CD1822159B35400777664 /* ShapeType.swift */,
Expand Down Expand Up @@ -277,10 +271,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
660F298A218D0C5E00038BE0 /* rockWall-2.scn in Resources */,
FE7CD15E2159ACB800777664 /* LaunchScreen.storyboard in Resources */,
3205083E215E9794000B63AF /* portland-concrete-effect-vinyl-flooring-grey.jpg in Resources */,
32261168215C54880041EE81 /* rockWall.scn in Resources */,
32050840215E9799000B63AF /* iS_makeitdouble.jpg in Resources */,
FE7CD15B2159ACB800777664 /* Assets.xcassets in Resources */,
FE7CD1592159ACB700777664 /* Main.storyboard in Resources */,
32F43FF921837D5D00591B41 /* SerialTest.scn in Resources */,
Expand Down
Binary file not shown.
43 changes: 18 additions & 25 deletions SJU-Rock-Wall/SJU-Rock-Wall/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,31 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Metal-->
<scene sceneID="yDF-D9-qSF">
<objects>
<navigationController id="y0h-90-Q1Q" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Metal" id="kKa-B9-n2f"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Ygr-ZP-LOD">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="BV1-FR-VrT" kind="relationship" relationship="rootViewController" id="Sqa-xQ-tlg"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ZdV-ul-1fm" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1807" y="257"/>
</scene>
<!--Graphics-->
<scene sceneID="tXr-a1-R10">
<objects>
<viewController storyboardIdentifier="Graphics" title="Graphics" id="BV1-FR-VrT" customClass="GameViewController" customModule="SJU_Rock_Wall" customModuleProvider="target" sceneMemberID="viewController">
<sceneKitView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="3se-qz-xqx">
<sceneKitView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" sceneName="rockWall.scn" id="3se-qz-xqx">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</sceneKitView>
<tabBarItem key="tabBarItem" title="Metal" id="jwM-4X-ejJ"/>
<navigationItem key="navigationItem" id="bvV-9h-dr8"/>
<navigationItem key="navigationItem" id="bvV-9h-dr8">
<barButtonItem key="rightBarButtonItem" title="Done" id="XaR-uj-TTk">
<connections>
<action selector="saveButtonPress:" destination="BV1-FR-VrT" id="t3c-C4-I1R"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="saveButton" destination="XaR-uj-TTk" id="Osk-Xb-Ib3"/>
<segue destination="T2B-7j-oE7" kind="show" identifier="saveScene" id="SW5-ua-9Bb"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="SZV-WD-TEh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1007" y="257"/>
<point key="canvasLocation" x="777" y="-2700"/>
</scene>
<!--UserProfile-->
<scene sceneID="Xzz-hY-cyy">
Expand Down Expand Up @@ -282,7 +275,6 @@
</tabBar>
<connections>
<segue destination="3gK-n8-lQT" kind="relationship" relationship="viewControllers" id="Ice-rU-u7a"/>
<segue destination="y0h-90-Q1Q" kind="relationship" relationship="viewControllers" id="Ufw-Jh-Ya0"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="fVI-WN-3VT" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -541,7 +533,7 @@
<navigationItem key="navigationItem" title="Routes" id="Kmy-rE-Urj">
<barButtonItem key="rightBarButtonItem" systemItem="add" id="BV9-cp-cFd">
<connections>
<segue destination="T2B-7j-oE7" kind="show" id="eVb-Rt-wyl"/>
<segue destination="BV1-FR-VrT" kind="show" id="WGB-ED-jSg"/>
</connections>
</barButtonItem>
</navigationItem>
Expand Down Expand Up @@ -686,7 +678,7 @@
<rect key="frame" x="16" y="192" width="49" height="30"/>
<state key="normal" title="Submit"/>
<connections>
<action selector="submitButtonPress:" destination="T2B-7j-oE7" eventType="touchUpInside" id="dms-6m-HyY"/>
<action selector="submitButtonPress:" destination="T2B-7j-oE7" eventType="touchUpInside" id="93l-uF-pp1"/>
</connections>
</button>
</subviews>
Expand All @@ -712,15 +704,16 @@
<outlet property="routeDescription" destination="N04-dF-04q" id="vYp-nC-NuU"/>
<outlet property="routeDifficulty" destination="0Eh-CP-Z6Y" id="Ug3-cj-niP"/>
<outlet property="routeName" destination="gE9-cx-niT" id="Rqe-bl-dE1"/>
<outlet property="submitButton" destination="acQ-kX-C5H" id="2fP-yy-uWq"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4hV-30-9fa" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="776.79999999999995" y="-2722.4887556221893"/>
<point key="canvasLocation" x="1713" y="-2700"/>
</scene>
</scenes>
<resources>
<image name="climbingClub" width="600" height="600"/>
<image name="climbingClub" width="300" height="300"/>
</resources>
<inferredMetricsTieBreakers>
<segue reference="boS-76-aO4"/>
Expand Down
19 changes: 4 additions & 15 deletions SJU-Rock-Wall/SJU-Rock-Wall/CreateRouteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,19 @@ import SceneKit

class CreateRouteViewController: UIViewController {

@IBOutlet weak var submitButton: UIBarButtonItem!
@IBOutlet weak var submitButton: UIButton!
@IBOutlet weak var routeName: UITextField!
@IBOutlet weak var routeDifficulty: UITextField!
@IBOutlet weak var routeDescription: UITextField!
private var sceneFile: SCNScene!
private var serialScene: String!

var serialScene: String!

private var uid: Any?

override func viewDidLoad() {
super.viewDidLoad()
uid = UserDefaults.standard.string(forKey: "uid")

sceneFile = SCNScene(named: "SerialTest.scn")

print(sceneFile)

let serializer = SceneSerializer.init(scene: sceneFile)
serialScene = serializer.serializeScene()
print(serialScene)

let unserialized = serializer.unserializeScene(serialScene: serialScene)
print(unserialized)

if (uid != nil) {
// something
}
Expand All @@ -46,7 +35,7 @@ class CreateRouteViewController: UIViewController {
let difficulty = routeDifficulty.text
let description = routeDescription.text

let json: [String: Any] = ["uid": uid!, "name": name!, "difficulty" : difficulty!, "description": description!, "wallState" : "NULL"]
let json: [String: Any] = ["uid": uid!, "name": name!, "difficulty" : difficulty!, "description": description!, "wallState" : serialScene!]

let jsonData = try? JSONSerialization.data(withJSONObject: json)

Expand Down
62 changes: 36 additions & 26 deletions SJU-Rock-Wall/SJU-Rock-Wall/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import QuartzCore
import SceneKit

class GameViewController: UIViewController {
@IBOutlet weak var saveButton: UIBarButtonItem!

var serialScene: String!

var scnView: SCNView!
var scnScene: SCNScene!
var cameraOrbit: SCNNode!
Expand Down Expand Up @@ -39,13 +43,11 @@ class GameViewController: UIViewController {
setupView()
setupScene()
setupCamera()
spawnShape()
// retrieve the wall node
wall = scnScene.rootNode.childNode(withName: "wall", recursively: true)!
// retrieve the wedge node
wedge = scnScene.rootNode.childNode(withName: "wedge", recursively: true)!
// retrieve the text node
text = scnScene.rootNode.childNode(withName: "text", recursively: true)!


let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
scnView.addGestureRecognizer(tapGesture)
Expand All @@ -59,6 +61,19 @@ class GameViewController: UIViewController {
scnView.addGestureRecognizer(pinchGesture)
}

@IBAction func saveButtonPress(_ sender: Any) {
let serializer = SceneSerializer.init(scene: scnScene)
serialScene = serializer.serializeScene()

self.performSegue(withIdentifier:"saveScene", sender: nil)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var descScene = segue.destination as! CreateRouteViewController
descScene.serialScene = serialScene
}


@objc
func handleTap(_ gestureRecognize: UIGestureRecognizer)
{
Expand All @@ -75,10 +90,18 @@ class GameViewController: UIViewController {
if(result.node.name != "text")
{
if((result.node.geometry!.firstMaterial?.emission.contents! as AnyObject).isEqual(UIColor.red))
{
result.node.geometry!.firstMaterial!.emission.contents = UIColor.yellow
}
else if((result.node.geometry!.firstMaterial?.emission.contents! as AnyObject).isEqual(UIColor.yellow))
{
result.node.geometry!.firstMaterial!.emission.contents = UIColor.orange
}
else if((result.node.geometry!.firstMaterial?.emission.contents! as AnyObject).isEqual(UIColor.orange))
{
result.node.geometry!.firstMaterial!.emission.contents = UIColor.black
}

else
{
result.node.geometry!.firstMaterial!.emission.contents = UIColor.red
Expand Down Expand Up @@ -155,7 +178,7 @@ class GameViewController: UIViewController {
return true
}
func setupView() {
scnView = self.view as! SCNView
scnView = self.view as? SCNView
// 1
scnView.showsStatistics = true
// 2
Expand All @@ -164,7 +187,14 @@ class GameViewController: UIViewController {
scnView.autoenablesDefaultLighting = true
}
func setupScene() {
scnScene = SCNScene(named: "rockWall.scn")
scnScene = SCNScene(named: "rockWall-2.scn")

let serializer = SceneSerializer.init(scene: scnScene)
let serialScene = serializer.serializeScene()
let unserialScene = serializer.unserializeScene(serialScene: serialScene)

scnScene = unserialScene

scnView.scene = scnScene
scnView.backgroundColor = UIColor.white
}
Expand Down Expand Up @@ -192,24 +222,4 @@ class GameViewController: UIViewController {

}

func spawnShape() {
// 1
/*var geometry:SCNGeometry
// 2
switch ShapeType.random() {
case .Box:
geometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 1.0)
case .Sphere:
geometry = SCNSphere(radius: 0.5)
case .Pyramid:
geometry = SCNPyramid(width: 1.0, height: 1.0, length: 1.0)
default:
// 3
geometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.0)
}
//
let geometryNode = SCNNode(geometry: geometry)
// 5
scnScene.rootNode.addChildNode(geometryNode)*/
}
}

0 comments on commit 1423926

Please sign in to comment.