useViewsAngleStore.js
4.59 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
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
import GRIDIMAGE from '@/views/assets/images/views-angle/grid.png';
import SECTIONVIEWIMAGE from '@/views/assets/images/views-angle/sectionView.png';
import FITIMAGE from '@/views/assets/images/views-angle/zoom-to-fit.png';
import FRONT from '@/views/assets/images/views-angle/front.png';
import BACK from '@/views/assets/images/views-angle/back.png';
import RIGHT from '@/views/assets/images/views-angle/right.png';
import LEFT from '@/views/assets/images/views-angle/left.png';
import TOP from '@/views/assets/images/views-angle/top.png';
import BOTTOM from '@/views/assets/images/views-angle/bottom.png';
import ANGLE from '@/views/assets/images/views-angle/angle.png';
import { Vector3 } from 'three';
import { defineStore, storeToRefs } from 'pinia';
import { useRoute } from 'vue-router';
import { watch, ref } from 'vue';
import { setCameraViewAngle } from '@/utility/jsm/viewAngleControl';
import { GRID_NAME, PLATFORM_NAME } from '@/utility/constants/mesh-named';
import { useEditorStore } from './useEditorStore';
export const useViewsAngleStore = defineStore('viewsAngle', () => {
const store = useEditorStore();
const { editor, isLoadEnd } = storeToRefs(store);
const { zoomToFit, setPlatformOpacity, setSectionViewControl } = store;
const route = useRoute();
const objectitems = ref([
{
key: 'grid',
image: GRIDIMAGE,
selected: true,
enabled: true
},
{
key: 'sectionview',
image: SECTIONVIEWIMAGE,
selected: false,
enabled: false
},
{
key: 'zoomtofit',
image: FITIMAGE,
selected: false,
enabled: true
}
]);
const viewitems = ref([
{
key: 'front',
image: FRONT
},
{
key: 'back',
image: BACK
},
{
key: 'right',
image: RIGHT
},
{
key: 'left',
image: LEFT
},
{
key: 'top',
image: TOP
},
{
key: 'bottom',
image: BOTTOM
},
{
key: 'angle',
image: ANGLE
}
]);
const view = ref('front');
const isSectionViewVisible = ref(false);
const setViewsAngle = (key) => {
if (!editor.value) return;
const { control, camera, container } = editor.value;
if (!control) return;
if (!camera) return;
camera.up.copy(new Vector3(0, 0, 1));
setCameraViewAngle(key, camera, control, container, new Vector3(), new Vector3());
setPlatformOpacity();
view.value = key;
};
const setZoomToFit = () => {
zoomToFit();
};
const setGridOnoff = (isVisible) => {
if (!editor.value) return;
const { scene } = editor.value;
if (!scene) return;
const mesh = scene.getObjectByName(GRID_NAME);
if (mesh) {
mesh.visible = isVisible;
}
};
const setSectionViewONoff = (isVisible) => {
isSectionViewVisible.value = isVisible;
setSectionViewControl(isVisible);
};
const handleClickObjects = (key) => {
const index = objectitems.value.findIndex((el) => el.key === key);
if (index > -1) {
if (key !== 'zoomtofit') objectitems.value[index].selected = !objectitems.value[index].selected;
if (!objectitems.value[index].enabled) return;
switch (key) {
case 'grid':
setGridOnoff(objectitems.value[index].selected);
break;
case 'sectionview':
setSectionViewONoff(objectitems.value[index].selected);
break;
case 'zoomtofit':
setZoomToFit();
break;
default:
break;
}
}
};
const setViewsObjectEnabled = (key = 'grid', isEnable = true) => {
const object = objectitems.value.find((el) => el.key === key);
if (object) {
object.enabled = isEnable;
}
};
watch(
() => isLoadEnd.value,
() => {
const { final_file } = route.query;
if (final_file) {
handleClickObjects('grid');
}
}
);
return {
objectitems,
viewitems,
isSectionViewVisible,
setViewsAngle,
setZoomToFit,
setGridOnoff,
setSectionViewONoff,
handleClickObjects,
setViewsObjectEnabled
};
});