Skip to content

Commit

Permalink
Also add some custom classes to contrcutor LUT
Browse files Browse the repository at this point in the history
  • Loading branch information
vidartf committed Oct 1, 2018
1 parent 583e914 commit a1579f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions js/src/_base/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ function getModelScene(model) {
}


var three_reverse_lut;
var threeReverseLut;
var customModelsLut = {};

/**
* Fund the unminified name of the constructor of a three object.
Expand All @@ -383,25 +384,31 @@ function lookupThreeConstructorName(obj) {
if (THREE[name] !== undefined) {
return name;
}
// Check against our custom classes:
if (customModelsLut[name] !== undefined) {
return customModelsLut[name];
}

// Assume constructor name is minified, try a reverse lookup
if (!three_reverse_lut) {
if (!threeReverseLut) {
// Build reverse LUT and store it
three_reverse_lut = Object.keys(THREE).reduce(function(res, key) {
threeReverseLut = Object.keys(THREE).reduce(function(res, key) {
var value = THREE[key];
if (!!value.prototype && !!value.prototype.constructor.name) {
res[value.prototype.constructor.name] = key;
}
return res;
}, {});
}
return three_reverse_lut[name];
return threeReverseLut[name];
}


module.exports = {
createModel: createModel,
computeBoundingSphere: computeBoundingSphere,
computeBoundingBox: computeBoundingBox,
customModelsLut: customModelsLut,
shrinkFrustumPlanes: shrinkFrustumPlanes,
safeFrustumPlanes: safeFrustumPlanes,
lookAtSphere: lookAtSphere,
Expand Down
4 changes: 4 additions & 0 deletions js/src/objects/CloneArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var Promise = require('bluebird');
var THREE = require('three');
var CloneArrayAutogen = require('./CloneArray.autogen').CloneArrayModel;

var utils = require('../_base/utils');


function ThreeCloneArray(original, positions, merge) {
THREE.Object3D.call(this);
Expand Down Expand Up @@ -149,6 +151,8 @@ var CloneArrayModel = CloneArrayAutogen.extend({

});

utils.customModelsLut[ThreeCloneArray.prototype.constructor.name] = 'CloneArray';

module.exports = {
CloneArrayModel: CloneArrayModel,
};

0 comments on commit a1579f9

Please sign in to comment.