nnnjjj123
2020-11-17 1b2c1edb61190eeb19f465ff031eaa3b2a1b8dbc
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
///////////////////////////////////////////////////////////////////////////
// Copyright © 2018 NarutoGIS. All Rights Reserved.
// 模块描述:模型加载,显示控制
///////////////////////////////////////////////////////////////////////////
define([
    "dojo/_base/declare",
    "dojo/_base/lang",
    'dojo/_base/html',
    "dojo/_base/fx",
    'jimu/BaseWidget'
],function(
    declare,
    lang,
    html,
    fx,
    BaseWidget
){
    //https://github.com/KhronosGroup/OpenCOLLADA/wiki/OpenCOLLADA-Tools
    //https://github.com/KhronosGroup/COLLADA2GLTF
 
 
    //http://www.xue51.com/soft/1810.html
 
    //https://blog.csdn.net/l491453302/article/details/46766909
    //https://blog.csdn.net/umgsoil/article/details/74572877
    //https://blog.csdn.net/HobHunter/article/details/75014054
    //https://blog.csdn.net/umgsoil/article/details/75352698
    //https://blog.csdn.net/y5492853/article/details/77046843?utm_source=blogxgwz0
 
    //COLLADA2GLTF-bin.exe -i e:\models\shafa3\shafa2.dae -s --doubleSided  新的不好使,动画导不出来
    return declare([BaseWidget], {
        baseClass: 'jimu-widget-ModelAdd',  
 
        postCreate:function(){ 
            this.inherited(arguments); 
        }, 
 
        startup:function(){
            this.inherited(arguments); 
        },
        onOpen: function () {
            //面板打开的时候触发 (when open this panel trigger)
            this.entity1?this.entity1.show=true:'';
 
            this.entity2?this.entity2.show=true:'';
        },
 
        onClose: function () {
            //面板关闭的时候触发 (when this panel is closed trigger)
            this.entity1?this.entity1.show=false:'';
 
            this.entity2?this.entity2.show=false:'';
        },
        loadModel:function(){
 
            if(this.entity1)return;
            //添加模型
            var position = Cesium.Cartesian3.fromDegrees(123.0744619, 44.0503706, 0);
            var heading = Cesium.Math.toRadians(0);
            var pitch = 0;
            var roll = 0;
            var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
            var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
 
            var entity1 = this.map.entities.add({
                name : "shafa",
                position : position,
                orientation : orientation,
                model : {
                    uri : './widgets/ModelAdd/models/shafa/shafa.gltf',
                    // minimumPixelSize : 128,
                    // maximumScale : 20000
                }
            });
 
            this.map.trackedEntity = entity1;
 
            this.entity1 = entity1;
 
        },
 
        loadAnimateModel:function(){
            if(this.entity2)return;
 
            //默认地球的动画状态是关闭的需要打开
            this.map.clock.shouldAnimate  = true;
 
            var origin = Cesium.Cartesian3.fromDegrees(123.0744619, 44.0504706, 0.0);
            var modelMatrix =  Cesium.Transforms.eastNorthUpToFixedFrame(origin);
            this.model =  this.map.scene.primitives.add(Cesium.Model.fromGltf({
                url : './widgets/ModelAdd/models/shafa2/shafa.gltf',
                modelMatrix : modelMatrix,
                show : true,                     // default
                scale : 2.0,                     // double size
                // minimumPixelSize : 128,          // never smaller than 128 pixels
                // maximumScale: 20000,             // never larger than 20000 * model size (overrides minimumPixelSize)
                allowPicking : false            // not pickable
            }));
 
            this.model.readyPromise.then(function(model) {
                // Play all animations when the model is ready to render
                model.activeAnimations.addAll({
                    speedup : 0.5,
                    loop:Cesium.ModelAnimationLoop.REPEAT
                });
            });
 
            this.map.trackedEntity = null;
 
            this.entity2 = this.model;
        },
        pause:function(){
            this.model.activeAnimations.removeAll();
        },
        speedUp:function(){
            this.model.activeAnimations.addAll({
                speedup : 2.5,
                loop:Cesium.ModelAnimationLoop.REPEAT
            });
        }
 
    });
});