~holger-seelig/x-ite/trunk-1

« back to all changes in this revision

Viewing changes to src/x_ite/Components/Navigation/LOD.js

  • Committer: Holger Seelig
  • Date: 2018-11-08 17:35:51 UTC
  • Revision ID: holger.seelig@yahoo.de-20181108173551-ur2hl5bd0q8wfssk
Fixed: Select first named proto found.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
{
71
71
"use strict";
72
72
 
73
 
        var
74
 
                FRAMES         = 180, // Number of frames after wich a level change takes in affect.
75
 
                FRAME_RATE_MIN = 20,  // Lowest level of detail.
76
 
                FRAME_RATE_MAX = 55;  // Highest level of detail.
77
 
        
78
73
        function LOD (executionContext)
79
74
        {
80
75
                X3DGroupingNode .call (this, executionContext);
106
101
                        new X3DFieldDefinition (X3DConstants .inputOnly,      "removeChildren",   new Fields .MFNode ()),
107
102
                        new X3DFieldDefinition (X3DConstants .inputOutput,    "children",         new Fields .MFNode ()),
108
103
                ]),
109
 
                modelViewMatrix: new Matrix4 (),
110
104
                getTypeName: function ()
111
105
                {
112
106
                        return "LOD";
147
141
 
148
142
                        return bbox .set (this .bboxSize_ .getValue (), this .bboxCenter_ .getValue ());
149
143
                },
150
 
                getLevel: function (browser, modelViewMatrix)
 
144
                getLevel: (function ()
151
145
                {
152
 
                        if (this .range_ .length === 0)
 
146
                        var
 
147
                                FRAMES         = 180, // Number of frames after wich a level change takes in affect.
 
148
                                FRAME_RATE_MIN = 20,  // Lowest level of detail.
 
149
                                FRAME_RATE_MAX = 55;  // Highest level of detail.
 
150
 
 
151
                        return function (browser, modelViewMatrix)
153
152
                        {
154
 
                                var size = this .children_ .length;
155
 
 
156
 
                                if (size < 2)
157
 
                                        return 0;
158
 
 
159
 
                                this .frameRate = ((FRAMES - 1) * this .frameRate + browser .currentFrameRate) / FRAMES;
160
 
 
161
 
                                if (size === 2)
162
 
                                        return Number (this .frameRate > FRAME_RATE_MAX);
163
 
 
164
 
                                var
165
 
                                        n        = size - 1,
166
 
                                        fraction = Math .max ((this .frameRate - FRAME_RATE_MIN) / (FRAME_RATE_MAX - FRAME_RATE_MIN), 0);
167
 
 
168
 
                                return Math .min (Math .ceil (fraction * (n - 1)), n);
169
 
                        }
170
 
 
171
 
                        var distance = this .getDistance (modelViewMatrix);
172
 
 
173
 
                        return Algorithm .upperBound (this .range_, 0, this .range_ .length, distance, Algorithm .less);
174
 
                },
 
153
                                if (this .range_ .length === 0)
 
154
                                {
 
155
                                        var size = this .children_ .length;
 
156
        
 
157
                                        if (size < 2)
 
158
                                                return 0;
 
159
        
 
160
                                        this .frameRate = ((FRAMES - 1) * this .frameRate + browser .currentFrameRate) / FRAMES;
 
161
        
 
162
                                        if (size === 2)
 
163
                                                return Number (this .frameRate > FRAME_RATE_MAX);
 
164
        
 
165
                                        var fraction = 1 - Algorithm .clamp ((this .frameRate - FRAME_RATE_MIN) / (FRAME_RATE_MAX - FRAME_RATE_MIN), 0, 1);
 
166
 
 
167
                                        return Math .min (Math .floor (fraction * size), size - 1);
 
168
                                }
 
169
        
 
170
                                var distance = this .getDistance (modelViewMatrix);
 
171
        
 
172
                                return Algorithm .upperBound (this .range_, 0, this .range_ .length, distance, Algorithm .less);
 
173
                        };
 
174
                })(),
175
175
                getDistance: function (modelViewMatrix)
176
176
                {
177
177
                        modelViewMatrix .translate (this .center_ .getValue ());
178
178
 
179
179
                        return modelViewMatrix .origin .abs ();
180
180
                },
181
 
                traverse: function (type, renderObject)
 
181
                traverse: (function ()
182
182
                {
183
 
                        if (! this .keepCurrentLevel)
 
183
                        var modelViewMatrix = new Matrix4 ();
 
184
 
 
185
                        return function (type, renderObject)
184
186
                        {
185
 
                                if (type === TraverseType .DISPLAY)
 
187
                                if (! this .keepCurrentLevel)
186
188
                                {
187
 
                                        var
188
 
                                                level        = this .getLevel (renderObject .getBrowser (), this .modelViewMatrix .assign (renderObject .getModelViewMatrix () .get ())),
189
 
                                                currentLevel = this .level_changed_ .getValue ();
190
 
        
191
 
                                        if (this .forceTransitions_ .getValue ())
192
 
                                        {
193
 
                                                if (level > currentLevel)
194
 
                                                        level = currentLevel + 1;
195
 
        
196
 
                                                else if (level < currentLevel)
197
 
                                                        level = currentLevel - 1;
198
 
                                        }
199
 
 
200
 
                                        if (level !== currentLevel)
201
 
                                        {
202
 
                                                this .level_changed_ = level;
203
 
                                
204
 
                                                this .child = this .getChild (Math .min (level, this .children_ .length - 1));
205
 
 
206
 
                                                this .set_cameraObjects__ ();
 
189
                                        if (type === TraverseType .DISPLAY)
 
190
                                        {
 
191
                                                var
 
192
                                                        level        = this .getLevel (renderObject .getBrowser (), modelViewMatrix .assign (renderObject .getModelViewMatrix () .get ())),
 
193
                                                        currentLevel = this .level_changed_ .getValue ();
 
194
 
 
195
                                                if (this .forceTransitions_ .getValue ())
 
196
                                                {
 
197
                                                        if (level > currentLevel)
 
198
                                                                level = currentLevel + 1;
 
199
                
 
200
                                                        else if (level < currentLevel)
 
201
                                                                level = currentLevel - 1;
 
202
                                                }
 
203
        
 
204
                                                if (level !== currentLevel)
 
205
                                                {
 
206
                                                        this .level_changed_ = level;
 
207
                                        
 
208
                                                        this .child = this .getChild (Math .min (level, this .children_ .length - 1));
 
209
        
 
210
                                                        this .set_cameraObjects__ ();
 
211
                                                }
207
212
                                        }
208
213
                                }
209
 
                        }
210
 
 
211
 
                        if (this .child)
212
 
                                this .child .traverse (type, renderObject);
213
 
                },
 
214
        
 
215
                                if (this .child)
 
216
                                        this .child .traverse (type, renderObject);
 
217
                        };
 
218
                })(),
214
219
        });
215
220
 
216
221
        return LOD;