-
Notifications
You must be signed in to change notification settings - Fork 28
/
StoryApplication.ts
200 lines (163 loc) · 6.88 KB
/
StoryApplication.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* 3D Foundation Project
* Copyright 2021 Smithsonian Institution
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import parseUrlParameter from "@ff/browser/parseUrlParameter";
import Commander from "@ff/core/Commander";
import System from "@ff/graph/System";
import CPickSelection from "@ff/scene/components/CPickSelection";
import documentTemplate from "client/templates/default.svx.json";
import ExplorerApplication, { IExplorerApplicationProps } from "./ExplorerApplication";
import storyTypes from "./storyTypes";
import CVStoryApplication from "../components/CVStoryApplication";
import CVAssetReader from "../components/CVAssetReader";
import CVAssetManager from "../components/CVAssetManager";
import CVMediaManager from "../components/CVMediaManager";
import CVDocumentProvider from "../components/CVDocumentProvider";
import CVDocument from "../components/CVDocument";
import NVTasks from "../nodes/NVTasks";
import NVoyagerStory from "../nodes/NVoyagerStory";
import MainView from "../ui/story/MainView";
import CVTaskProvider, { ETaskMode } from "../components/CVTaskProvider";
import CVStandaloneFileManager from "client/components/CVStandaloneFileManager";
////////////////////////////////////////////////////////////////////////////////
/**
* Initial properties of the Voyager Story main [[StoryApplication]].
*/
export interface IStoryApplicationProps extends IExplorerApplicationProps
{
/** The page URL to navigate to when the user exits the story tool. */
referrer?: string;
/** The task set the application should display. Valid options: "prep","author","qc","expert","standalone". */
mode?: string;
/** When set to true, application displays additional expert level tools. */
expert?: boolean;
/** When set to true, application supports dragging and dropping files. */
dragdrop?: boolean;
}
/**
* Voyager Story main application.
*/
export default class StoryApplication
{
readonly props: IStoryApplicationProps;
readonly explorer: ExplorerApplication;
readonly system: System;
readonly commander: Commander;
protected get assetReader() {
return this.system.getMainComponent(CVAssetReader);
}
protected get assetManager() {
return this.system.getMainComponent(CVAssetManager);
}
protected get mediaManager() {
return this.system.getMainComponent(CVMediaManager);
}
protected get documentProvider() {
return this.system.getMainComponent(CVDocumentProvider);
}
constructor(parent: HTMLElement, props?: IStoryApplicationProps)
{
// create the embedded explorer application, parse properties, start loading/presenting
this.explorer = new ExplorerApplication(null, props, /* embedded */ true);
this.props = props || {};
this.system = this.explorer.system;
this.commander = this.explorer.commander;
// register additional story tool components
const registry = this.system.registry;
registry.add(storyTypes);
//this.logController = new LogController(this.system, this.commander);
// add story components
this.system.graph.createCustomNode(NVoyagerStory, "Story");
this.system.graph.createCustomNode(NVTasks, "Tasks");
// enable viewport brackets
this.system.getMainComponent(CPickSelection).ins.viewportBrackets.setValue(true);
if (parent) {
// create a view and attach to parent
new MainView(this).appendTo(parent);
}
// initialize default document
this.documentProvider.createDocument(documentTemplate as any);
this.evaluateProps();
}
setBaseUrl(url: string)
{
this.assetManager.baseUrl = url;
this.mediaManager.rootUrl = url;
}
loadDocument(documentPath: string, merge?: boolean): Promise<CVDocument>
{
return this.assetReader.getJSON(documentPath)
.then(data => this.documentProvider.amendDocument(data, documentPath, merge))
.catch(error => {
console.warn(`error while loading document: ${error.message}`);
throw error;
});
}
loadModel(modelPath: string, quality: string)
{
return this.documentProvider.appendModel(modelPath, quality);
}
loadGeometry(geoPath: string, colorMapPath?: string,
occlusionMapPath?: string, normalMapPath?: string, quality?: string)
{
return this.documentProvider.appendGeometry(
geoPath, colorMapPath, occlusionMapPath, normalMapPath, quality);
}
protected evaluateProps()
{
const props = this.props;
props.referrer = props.referrer || parseUrlParameter("referrer");
props.mode = props.mode || parseUrlParameter("mode") || "prep";
props.expert = props.expert !== undefined ? props.expert : parseUrlParameter("expert") !== "false";
props.dragdrop = props.dragdrop || false;
// If in standalone mode, remove root and document params that may be present
const modeText = props.mode.toLowerCase();
if (modeText.startsWith("stand")) {
const revisedUrl = new URL(window.location.href);
revisedUrl.searchParams.delete("root");
revisedUrl.searchParams.delete("document");
window.history.replaceState(null,null,revisedUrl);
props.root = null;
props.document = null;
}
this.explorer.evaluateProps();
const app = this.system.getMainComponent(CVStoryApplication);
app.referrer = props.referrer;
let mode = ETaskMode.Edit;
if (modeText.startsWith("au")) {
mode = ETaskMode.Authoring;
}
else if (modeText.startsWith("qc")) {
mode = ETaskMode.QC;
}
else if (modeText.startsWith("ex")) {
mode = ETaskMode.Expert;
}
else if (modeText.startsWith("stand")) {
mode = ETaskMode.Standalone;
props.dragdrop = true;
app.createComponent(CVStandaloneFileManager);
}
// if dragging/dropping have to assume that a non-loading url is still valid
if(props.dragdrop === true) {
this.assetManager.ins.baseUrlValid.setValue(true);
}
this.mediaManager.rootUrl = this.assetManager.baseUrl;
const tasks = this.system.getMainComponent(CVTaskProvider);
tasks.ins.mode.setValue(mode);
}
}
window["VoyagerStory"] = StoryApplication;