-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscenebuilder.js
More file actions
114 lines (106 loc) · 3.33 KB
/
scenebuilder.js
File metadata and controls
114 lines (106 loc) · 3.33 KB
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
var sceneModels = [];
var receivedFirstScene = false;
var currentScene = {};
function renderInBody() {
document.body.innerHTML = "";
renderer.setPixelRatio(window.devicePixelRatio);
createBaseScene(window.innerWidth,window.innerHeight);
document.body.appendChild(renderer.domElement);
}
function renderInPanel(width,height) {
var panel = document.getElementById("3dscene");
renderer.setPixelRatio(window.devicePixelRatio);
createBaseScene(width,height);
panel.appendChild(renderer.domElement);
}
function receiveSceneData(data) {
console.log("receive scene data");
console.log(data);
if(receivedFirstScene == false) {
receivedFirstScene = true;
buildInitialScene(data);
} else {
updateScene(data);
}
}
function updateScene(data) {
placeModels(data.models);
if(currentScene.skybox != data.skybox || currentScene.skyboxSize != data.skyboxSize || currentScene.skyboxPos != data.skyboxPos) {
setSkyboxStage(scene,data.skybox,data.skyboxSize,data.skyboxPos);
}
currentScene = data;
}
function buildInitialScene(data) {
currentScene = data;
setSkyboxStage(scene,data.skybox,data.skyboxSize,data.skyboxPos);
var models = data.models;
placeModels(models);
startInteraction();
//testReticulum();
}
function findModelInScene(path) {
console.log("scene models");
console.log(sceneModels);
for(var i=0;i<sceneModels.length;i++) {
var model = sceneModels[i];
if(model.id === path) {
return model.scene;
}
}
return null;
}
function placeModels(models) {
models.forEach(function(model) {
var modelInScene = findModelInScene(model.path);
if(modelInScene != null) {
console.log("model already in scene");
//update parameters, already in scene
modelInScene.position.x = model.posx;
modelInScene.position.y = model.posy;
modelInScene.position.z = model.posz;
modelInScene.rotation.x = model.rotx;
modelInScene.rotation.y = model.roty;
modelInScene.rotation.z = model.rotz;
stopSpin(modelInScene);
if(model.spin == 'true') {
if(model.spinaxis.toUpperCase() == 'X') {
startSpin(modelInScene,1,0,0);
} else if(model.spinaxis.toUpperCase() == 'Y') {
startSpin(modelInScene,0,1,0);
} else if(model.spinaxis.toUpperCase() == 'Z') {
startSpin(modelInScene,0,0,1);
}
}
scaleModel(modelInScene,model.scale);
} else {
loadDAE(getModelPathFromServer(model.path),function(result) {
if(model.posx == 0 && model.posy == 0 && model.posz == 0) {
placeModelInFrontOfCamera(result.scene);
} else {
result.scene.position.x = model.posx;
result.scene.position.y = model.posy;
result.scene.position.z = model.posz;
}
result.scene.rotation.x = model.rotx;
result.scene.rotation.y = model.roty;
result.scene.rotation.z = model.rotz;
console.log("scene uuid: " + result.scene.uuid);
stopSpin(result.scene);
if(model.spin == 'true') {
if(model.spinaxis.toUpperCase() == 'X') {
startSpin(result.scene,1,0,0);
} else if(model.spinaxis.toUpperCase() == 'Y') {
startSpin(result.scene,0,1,0);
} else if(model.spinaxis.toUpperCase() == 'Z') {
startSpin(result.scene,0,0,1);
}
}
scaleModel(result.scene,model.scale);
console.log("Result scene:");
console.log(result.scene);
sceneModels.push({scene: result.scene, id: model.path, originalScale: result.scene.scal});
scene.add(result.scene);
});
}
});
}