Skip to content

Commit cddc3bf

Browse files
committed
Add util function for getting unminified three name
1 parent 353fb39 commit cddc3bf

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

js/src/_base/Three.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ var ThreeModel = widgets.WidgetModel.extend({
188188
this.initialized_from_three[propName] = true;
189189
var obj = this.obj[propName];
190190
// First, we need to figure out which model constructor to use
191-
var ctorName = obj.constructor.name + 'Model';
191+
var ctorName = utils.lookupThreeConstructorName(obj) + 'Model';
192192
var index = require('../');
193193
var ctor = index[ctorName];
194194
// Create the model

js/src/_base/utils.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,31 @@ function getModelScene(model) {
376376
}
377377

378378

379+
var three_reverse_lut;
380+
381+
/**
382+
* Fund the unminified name of the constructor of a three object.
383+
*/
384+
function lookupThreeConstructorName(obj) {
385+
var name = obj.constructor.name;
386+
if (THREE[name] !== undefined) {
387+
return name;
388+
}
389+
// Assume constructor name is minified, try a reverse lookup
390+
if (!three_reverse_lut) {
391+
// Build reverse LUT and store it
392+
three_reverse_lut = Object.keys(THREE).reduce(function(res, key) {
393+
var value = THREE[key];
394+
if (!!value.prototype && !!value.prototype.constructor.name) {
395+
res[value.prototype.constructor.name] = key;
396+
}
397+
return res;
398+
}, {});
399+
}
400+
return three_reverse_lut[name];
401+
}
402+
403+
379404
module.exports = {
380405
createModel: createModel,
381406
computeBoundingSphere: computeBoundingSphere,
@@ -389,4 +414,5 @@ module.exports = {
389414
nestedDiff: nestedDiff,
390415
getObjectScene: getObjectScene,
391416
getModelScene: getModelScene,
417+
lookupThreeConstructorName: lookupThreeConstructorName,
392418
};

js/src/materials/Material.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var MaterialModel = MaterialAutogen.extend({
1111
break;
1212
default:
1313
MaterialAutogen.prototype.onCustomMessage.call(arguments);
14-
1514
}
1615
},
1716

0 commit comments

Comments
 (0)