surprise
2023-12-05 6ecef4176f6d9df60cd1a753a36e09cd96bce9b8
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
export default {
    methods: {
        toFixed(num, length) {
            return parseFloat(num).toFixed(length);
        },
        removeModel(model) {
            if (model) {
                model.deleteObject
                    ? model.deleteObject()
                    : Viewer.entities.remove(model);
            }
        },
        changeModelAngle(model) {
            if (this.type === "b3dm") {
                model.setEditData({
                    roll: this.data.roll,
                    pitch: this.data.pitch,
                    heading: this.data.heading
                })
            } else {
                model.orientation = Cesium.Transforms.headingPitchRollQuaternion(
                    model.position.getValue(),
                    new Cesium.HeadingPitchRoll(
                        Cesium.Math.toRadians(Cesium.defaultValue(this.data.heading, 0)),
                        Cesium.Math.toRadians(Cesium.defaultValue(this.data.pitch, 0)),
                        Cesium.Math.toRadians(Cesium.defaultValue(this.data.roll, 0))
                    )
                );
            }
 
        },
        changeModelPosition(model) {
            if (this.type === "b3dm") {
                if (this.setPositionType === "height") {
                    model.setHeight(this.data.height);
                } else {
                    model.setPosition([this.data.lon, this.data.lat, this.data.height]);
                }
            } else if (this.type === "gltf") {
                model.position = Cesium.Cartesian3.fromDegrees(this.data.lon, this.data.lat, this.data.height);
            }
        },
        changeModelScale(model) {
            model.model.scale = this.data.scale;
        },
        // 编辑模型
        editModel(editType, model) {
            if (editType === "lon" || editType === "lat" || editType === "height") {
                this.changeModelPosition(model, editType);
            } else if (editType === "scale") {
                this.changeModelScale(model);
            } else if (editType === "setPositionType") {
                if (this.setPositionType === "height") {
                    model.setHeight(this.data.height);
                } else {
                    this.data.lon = this.toFixed(model.modelEditData.lon, 6);
                    this.data.lat = this.toFixed(model.modelEditData.lat, 6);
                    this.data.heading = model.modelEditData.heading;
                    this.data.pitch = model.modelEditData.pitch;
                    this.data.roll = model.modelEditData.roll;
                    model.setPosition([this.data.lon, this.data.lat, this.data.height]);
                }
            } else if (editType === "setPosition") {
                if (this.setPosition) {
                    this.data.height = this.toFixed(model.modelEditData.height, 2);
                    this.editModel("setPositionType", model);
                } else {
                    model.restore();
                }
            } else if (editType === "maximumScreenSpaceError") {
                model.item.maximumScreenSpaceError = this.data.maximumScreenSpaceError || 16;
            } else if (editType === "backFaceCulling") {
                model.item.backFaceCulling = !this.data.backFaceCulling;
            } else if (editType === "maximumMemoryUsage") {
                model.item.maximumMemoryUsage = this.data.maximumMemoryUsage || 512;
            } else if (editType === "geometricError" && this.data.geometricError) {
                model.item._geometricError = this.data.geometricError;
            } else if (editType === "color") {
                model.item.style = new Cesium.Cesium3DTileStyle(model.setStyle({
                    colors: this.data.color
                }));
            } else if (editType === "heading" || editType === "pitch" || editType === "roll") {
                this.changeModelAngle(model);
            } else if (editType === 'effects' || editType === 'effectsMaxHeight') {
                model[editType] = this.data[editType];
            }
        },
        // 还原
        restore(model) {
            if (this.changeModel) {
                this.removeModel(model);
                sgworld._treeTool.addData(this.defaultEditData);
            } else if (this.type === "b3dm") {
                if (this.defaultEditData.modelHeight != undefined) {
                    model.setHeight(this.defaultEditData.modelHeight);
                } else if (this.defaultEditData.Center != undefined) {
                    model.setPosition(this.defaultEditData.Center);
                    model.setEditData({
                        roll: this.defaultEditData.roll || 0,
                        pitch: this.defaultEditData.pitch || 0,
                        heading: this.defaultEditData.heading || 0
                    })
                } else {
                    model.restore();
                }
                if (this.defaultEditData.maximumScreenSpaceError) {
                    model.item.maximumScreenSpaceError = this.defaultEditData.maximumScreenSpaceError || 16;
                }
                if (this.defaultEditData.backFaceCulling !== undefined) {
                    model.item.backFaceCulling = !this.defaultEditData.backFaceCulling;
                }
                if (this.defaultEditData.color) {
                    model.item.style = new Cesium.Cesium3DTileStyle(model.setStyle({
                        colors: this.defaultEditData.color
                    }));
                } else {
                    model.item.style = new Cesium.Cesium3DTileStyle(model.setStyle({
                        colors: `rgba(255,255,255,${this.defaultEditData.alpha || 1})`
                    }));
                }
            } else if (this.type === "gltf") {
                model.position = Cesium.Cartesian3.fromDegrees(this.defaultEditData.lon, this.defaultEditData.lat, this.defaultEditData.height);
                model.model.scale = this.defaultEditData.scale;
                if (this.defaultEditData.heading || this.defaultEditData.pitch || this.defaultEditData.roll) {
                    model.orientation = Cesium.Transforms.headingPitchRollQuaternion(
                        model.position.getValue(),
                        new Cesium.HeadingPitchRoll(
                            Cesium.Math.toRadians(Cesium.defaultValue(this.defaultEditData.heading, 0)),
                            Cesium.Math.toRadians(Cesium.defaultValue(this.defaultEditData.pitch, 0)),
                            Cesium.Math.toRadians(Cesium.defaultValue(this.defaultEditData.roll, 0))
                        )
                    );
                } else {
                    model.orientation = undefined
                }
            }
        },
    },
};