Skip to content

Commit

Permalink
3Dオブジェクトをグリッド形式で表示する (#8)
Browse files Browse the repository at this point in the history
* refactor: SphereをSceneObjectにリネーム

* chore: サムネイル画像を追加

* feat: オブジェクトをグリッド形式で表示
  • Loading branch information
tsutsuken authored Aug 27, 2023
1 parent 3d62bfe commit 590607d
Show file tree
Hide file tree
Showing 23 changed files with 214 additions and 104 deletions.
16 changes: 8 additions & 8 deletions LaboVisionOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/* Begin PBXBuildFile section */
BE20EAD82A6AB78C00F5C869 /* ModelDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE20EAD72A6AB78C00F5C869 /* ModelDetailView.swift */; };
BE20EADA2A6ABA0E00F5C869 /* AppViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE20EAD92A6ABA0E00F5C869 /* AppViewModel.swift */; };
BE2F67F72A6BEBD70097C334 /* WindowToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE2F67F62A6BEBD70097C334 /* WindowToggle.swift */; };
BE72FF122A660DA600561E5D /* Sphere.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE72FF112A660DA600561E5D /* Sphere.swift */; };
BE72FF122A660DA600561E5D /* SceneObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE72FF112A660DA600561E5D /* SceneObject.swift */; };
BE9D696E2A7340B80038AFBD /* MenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE9D696D2A7340B80038AFBD /* MenuItem.swift */; };
BEEAE8952A6400B0003160CD /* RealityKitContent in Frameworks */ = {isa = PBXBuildFile; productRef = BEEAE8942A6400B0003160CD /* RealityKitContent */; };
BEEAE8972A6400B0003160CD /* LaboVisionOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEEAE8962A6400B0003160CD /* LaboVisionOSApp.swift */; };
BEEAE8992A6400B0003160CD /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEEAE8982A6400B0003160CD /* ContentView.swift */; };
Expand All @@ -32,8 +32,8 @@
/* Begin PBXFileReference section */
BE20EAD72A6AB78C00F5C869 /* ModelDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelDetailView.swift; sourceTree = "<group>"; };
BE20EAD92A6ABA0E00F5C869 /* AppViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppViewModel.swift; sourceTree = "<group>"; };
BE2F67F62A6BEBD70097C334 /* WindowToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowToggle.swift; sourceTree = "<group>"; };
BE72FF112A660DA600561E5D /* Sphere.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sphere.swift; sourceTree = "<group>"; };
BE72FF112A660DA600561E5D /* SceneObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneObject.swift; sourceTree = "<group>"; };
BE9D696D2A7340B80038AFBD /* MenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItem.swift; sourceTree = "<group>"; };
BEEAE88F2A6400B0003160CD /* LaboVisionOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LaboVisionOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
BEEAE8932A6400B0003160CD /* RealityKitContent */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = RealityKitContent; sourceTree = "<group>"; };
BEEAE8962A6400B0003160CD /* LaboVisionOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaboVisionOSApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -66,7 +66,8 @@
BE72FF102A660D9400561E5D /* Models */ = {
isa = PBXGroup;
children = (
BE72FF112A660DA600561E5D /* Sphere.swift */,
BE72FF112A660DA600561E5D /* SceneObject.swift */,
BE9D696D2A7340B80038AFBD /* MenuItem.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -97,7 +98,6 @@
BEEAE8982A6400B0003160CD /* ContentView.swift */,
BE20EAD72A6AB78C00F5C869 /* ModelDetailView.swift */,
BE20EAD92A6ABA0E00F5C869 /* AppViewModel.swift */,
BE2F67F62A6BEBD70097C334 /* WindowToggle.swift */,
BE72FF102A660D9400561E5D /* Models */,
BEEAE89A2A6400B4003160CD /* Assets.xcassets */,
BEEAE89C2A6400B4003160CD /* Preview Content */,
Expand Down Expand Up @@ -255,12 +255,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BE9D696E2A7340B80038AFBD /* MenuItem.swift in Sources */,
BE20EADA2A6ABA0E00F5C869 /* AppViewModel.swift in Sources */,
BE2F67F72A6BEBD70097C334 /* WindowToggle.swift in Sources */,
BEEAE8992A6400B0003160CD /* ContentView.swift in Sources */,
BE20EAD82A6AB78C00F5C869 /* ModelDetailView.swift in Sources */,
BEEAE8972A6400B0003160CD /* LaboVisionOSApp.swift in Sources */,
BE72FF122A660DA600561E5D /* Sphere.swift in Sources */,
BE72FF122A660DA600561E5D /* SceneObject.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion LaboVisionOS/AppViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ import Observation
class AppViewModel {
var isShowingModelDetail: Bool = false
let windowGroupModelDetail = "WindowGroupModelDetail"
var selectedSphere: Sphere? = .red
var selectedMenuItem: MenuItem? = .local
var selectedSceneObject: SceneObject? = .redSphere
}
6 changes: 3 additions & 3 deletions LaboVisionOS/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
6 changes: 6 additions & 0 deletions LaboVisionOS/Assets.xcassets/Thumbnail/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "SphereBlue.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions LaboVisionOS/Assets.xcassets/Thumbnail/Sphere/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "SphereRed.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "SphereYellow.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 34 additions & 16 deletions LaboVisionOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,51 @@ import RealityKitContent

struct ContentView: View {
@Environment(AppViewModel.self) private var appViewModel
@Environment(\.openWindow) private var openWindow

let sceneObjects: [SceneObject] = [.redSphere, .blueSphere, .yellowSphere]

var body: some View {
@Bindable var appViewModel = appViewModel

NavigationSplitView {
List(Sphere.allCases, selection: $appViewModel.selectedSphere) { sphere in
Text(sphere.title)
List(MenuItem.allCases, selection: $appViewModel.selectedMenuItem) { menuItem in
Text(menuItem.title)
.contentShape(Rectangle())
.onTapGesture {
appViewModel.selectedSphere = sphere
appViewModel.selectedMenuItem = menuItem
}
}
.navigationTitle("Spheres")
.navigationTitle("Menu")
} detail: {
VStack {
Model3D(named: appViewModel.selectedSphere?.modelName ?? "", bundle: realityKitContentBundle)
.padding(.bottom, 50)

Text(appViewModel.selectedSphere?.description ?? "")
WindowToggle(
title: "別ウィンドウで表示",
id: appViewModel.windowGroupModelDetail,
isShowing: $appViewModel.isShowingModelDetail
)
switch appViewModel.selectedMenuItem {
case .local:
ScrollView {
LazyVGrid(columns: Array(repeating: GridItem(), count: 2)) {
ForEach(sceneObjects, id: \.self) { sceneObject in
VStack {
Image(sceneObject.thumbnailPath)
.resizable()
.frame(width: 200, height: 200)
Text(sceneObject.description)
Button {
appViewModel.selectedSceneObject = sceneObject
openWindow(id: appViewModel.windowGroupModelDetail)
} label: {
Text("ウィンドウで表示")
}
}
}
}
}
.navigationTitle("Local")
.padding()
case .online:
EmptyView()
case .none:
EmptyView()
}
.navigationTitle("Sphere")
.padding()

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion LaboVisionOS/ModelDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ModelDetailView: View {
var body: some View {
VStack {
RealityView { content in
if let scene = try? await Entity(named: appViewModel.selectedSphere?.modelName ?? "", in: realityKitContentBundle) {
if let scene = try? await Entity(named: appViewModel.selectedSceneObject?.modelName ?? "", in: appViewModel.selectedSceneObject?.bundle) {
content.add(scene)
}
}
Expand Down
23 changes: 23 additions & 0 deletions LaboVisionOS/Models/MenuItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MenuItem.swift
// LaboVisionOS
//
// Created by Ken Tsutsumi on 2023/07/28.
//

import Foundation

enum MenuItem: Identifiable, CaseIterable {
case local, online
var id: Self { self }

var title: String {
switch self {
case .local:
return "Local"
case .online:
return "Online"
}
}

}
62 changes: 62 additions & 0 deletions LaboVisionOS/Models/SceneObject.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// SceneObject.swift
// LaboVisionOS
//
// Created by Ken Tsutsumi on 2023/07/18.
//

import Foundation
import RealityKitContent

enum SceneObject: String, Identifiable, CaseIterable {
case redSphere, blueSphere, yellowSphere
var id: Self { self }

var title: String {
switch self {
case .redSphere:
return "Red"
case .blueSphere:
return "Blue"
case .yellowSphere:
return "Yellow"
}
}

var description: String {
switch self {
case .redSphere:
return "This is red sphere"
case .blueSphere:
return "This is blue sphere"
case .yellowSphere:
return "This is yellow sphere"
}
}

var modelName: String {
switch self {
case .redSphere:
return "Sphere_Red"
case .blueSphere:
return "Sphere_Blue"
case .yellowSphere:
return "Sphere_Yellow"
}
}

var thumbnailPath: String {
switch self {
case .redSphere:
return "RedSphere"
case .blueSphere:
return "BlueSphere"
case .yellowSphere:
return "YellowSphere"
}
}

var bundle: Bundle? {
return realityKitContentBundle
}
}
46 changes: 0 additions & 46 deletions LaboVisionOS/Models/Sphere.swift

This file was deleted.

Loading

0 comments on commit 590607d

Please sign in to comment.