@xviewer.js/core 1.0.0-alpha.13 → 1.0.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -137,6 +137,10 @@ function mixin(derivedCtor, baseCtors) {
137
137
  });
138
138
  }
139
139
 
140
+ function getClassInstance(constructor, args = []) {
141
+ return typeof constructor === "function" ? new constructor(...args) : constructor;
142
+ }
143
+
140
144
  /**
141
145
  * The Ease class provides a collection of easing functions for use with tween.js.
142
146
  */ var Easing = {
@@ -1186,18 +1190,36 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1186
1190
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1187
1191
  };
1188
1192
 
1193
+ class ClassProperties {
1194
+ property(propertyKey, options = {}) {
1195
+ this._properties[propertyKey] = options;
1196
+ return this;
1197
+ }
1198
+ applyProperties(target) {
1199
+ Object.assign(target, this._properties);
1200
+ return target;
1201
+ }
1202
+ constructor(clsName){
1203
+ this.clsName = clsName;
1204
+ this._properties = Object.create(null);
1205
+ }
1206
+ }
1189
1207
  class PropertyManager {
1190
- static _getProperties(target) {
1191
- return PropertyManager._propertiesMap.get(target.constructor);
1208
+ static _hasProperties(constructor) {
1209
+ return PropertyManager._propertyMap.has(constructor);
1192
1210
  }
1193
- static _hasProperties(target) {
1194
- return PropertyManager._propertiesMap.has(target.constructor);
1211
+ static _getProperties(constructor, autoAdd = true) {
1212
+ let props = PropertyManager._propertyMap.get(constructor);
1213
+ if (props === undefined && autoAdd) {
1214
+ props = Object.create(null);
1215
+ PropertyManager._propertyMap.set(constructor, props);
1216
+ }
1217
+ return props;
1195
1218
  }
1196
- static _getMergedProperties(target) {
1219
+ static _getMergedProperties(constructor) {
1197
1220
  let props = null;
1198
- let constructor = target.constructor;
1199
1221
  while(constructor !== Object.constructor.prototype){
1200
- let values = PropertyManager._propertiesMap.get(constructor);
1222
+ let values = PropertyManager._getProperties(constructor, false);
1201
1223
  if (values) {
1202
1224
  if (props === null) {
1203
1225
  props = Object.create(null);
@@ -1208,17 +1230,29 @@ class PropertyManager {
1208
1230
  }
1209
1231
  return props;
1210
1232
  }
1233
+ static _getClassProperties(clsName, autoAdd = true) {
1234
+ let props = PropertyManager._classMap.get(clsName);
1235
+ if (props === undefined && autoAdd) {
1236
+ props = new ClassProperties(clsName);
1237
+ PropertyManager._classMap.set(clsName, props);
1238
+ }
1239
+ return props;
1240
+ }
1241
+ static _applyClassProperties(clsName, constructor) {
1242
+ let cls = PropertyManager._getClassProperties(clsName, false);
1243
+ if (cls) {
1244
+ return cls.applyProperties(PropertyManager._getProperties(constructor));
1245
+ } else {
1246
+ return PropertyManager._getProperties(constructor, false);
1247
+ }
1248
+ }
1211
1249
  }
1212
- PropertyManager._propertiesMap = new Map();
1250
+ PropertyManager._classMap = new Map();
1251
+ PropertyManager._propertyMap = new Map();
1213
1252
  function property(target, propertyKey) {
1214
1253
  let options = null;
1215
1254
  function normalized(target, propertyKey) {
1216
- let targetMap = PropertyManager._propertiesMap.get(target.constructor);
1217
- if (targetMap === undefined) {
1218
- targetMap = Object.create(null);
1219
- PropertyManager._propertiesMap.set(target.constructor, targetMap);
1220
- }
1221
- targetMap[propertyKey] = options;
1255
+ PropertyManager._getProperties(target.constructor)[propertyKey] = options;
1222
1256
  }
1223
1257
  if (target === undefined) {
1224
1258
  return property({});
@@ -2292,6 +2326,53 @@ class Plane extends three.Mesh {
2292
2326
  }
2293
2327
  }
2294
2328
 
2329
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2330
+ try {
2331
+ var info = gen[key](arg);
2332
+ var value = info.value;
2333
+ } catch (error) {
2334
+ reject(error);
2335
+ return;
2336
+ }
2337
+ if (info.done) resolve(value);
2338
+ else Promise.resolve(value).then(_next, _throw);
2339
+ }
2340
+ function _async_to_generator(fn) {
2341
+ return function() {
2342
+ var self = this, args = arguments;
2343
+
2344
+ return new Promise(function(resolve, reject) {
2345
+ var gen = fn.apply(self, args);
2346
+
2347
+ function _next(value) {
2348
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
2349
+ }
2350
+
2351
+ function _throw(err) {
2352
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
2353
+ }
2354
+
2355
+ _next(undefined);
2356
+ });
2357
+ };
2358
+ }
2359
+
2360
+ function _object_without_properties_loose(source, excluded) {
2361
+ if (source == null) return {};
2362
+
2363
+ var target = {};
2364
+ var sourceKeys = Object.keys(source);
2365
+ var key, i;
2366
+
2367
+ for (i = 0; i < sourceKeys.length; i++) {
2368
+ key = sourceKeys[i];
2369
+ if (excluded.indexOf(key) >= 0) continue;
2370
+ target[key] = source[key];
2371
+ }
2372
+
2373
+ return target;
2374
+ }
2375
+
2295
2376
  class Caller {
2296
2377
  get pause() {
2297
2378
  return this._pause;
@@ -2796,7 +2877,12 @@ class ResourceManager {
2796
2877
  this._loaders.set(ext, loader);
2797
2878
  }
2798
2879
  }
2799
- loadAsset({ url, ext, onProgress, ...props }) {
2880
+ loadAsset(_param) {
2881
+ var { url, ext, onProgress } = _param, props = _object_without_properties_loose(_param, [
2882
+ "url",
2883
+ "ext",
2884
+ "onProgress"
2885
+ ]);
2800
2886
  return new Promise((resolve, reject)=>{
2801
2887
  const info = ResourceManager._parseURL(url);
2802
2888
  const texSettings = ResourceManager._splitTextureSettings(props);
@@ -2897,7 +2983,7 @@ class PluginManager {
2897
2983
  return ins;
2898
2984
  }
2899
2985
  addPlugin(plugin) {
2900
- const ins = Viewer._getClassInstance(plugin);
2986
+ const ins = getClassInstance(plugin);
2901
2987
  if (this._pluginsMap.has(ins.constructor)) {
2902
2988
  Logger.warn("Plugin already added");
2903
2989
  } else {
@@ -2905,6 +2991,7 @@ class PluginManager {
2905
2991
  ins.install && ins.install();
2906
2992
  this._plugins.push(ins);
2907
2993
  this._pluginsMap.set(ins.constructor, ins);
2994
+ PropertyManager._applyClassProperties(ins.type, ins.constructor);
2908
2995
  }
2909
2996
  return ins;
2910
2997
  }
@@ -2925,9 +3012,6 @@ class PluginManager {
2925
3012
  }
2926
3013
 
2927
3014
  class Viewer extends EventEmitter {
2928
- static _getClassInstance(constructor, args = []) {
2929
- return typeof constructor === "function" ? new constructor(...args) : constructor;
2930
- }
2931
3015
  static _setDirectLightShadow(shadow, props) {
2932
3016
  const shadowCamera = shadow.camera;
2933
3017
  for(let i = 0; i < props.length && i < 6; i++){
@@ -3155,20 +3239,30 @@ class Viewer extends EventEmitter {
3155
3239
  addLoader(Loader) {
3156
3240
  this._resourceManager.addLoader(Loader);
3157
3241
  }
3158
- async load({ url, ext, onProgress, castShadow = false, receiveShadow = false, ...props }) {
3159
- const node = await this.loadAsset({
3160
- url,
3161
- ext,
3162
- onProgress
3163
- });
3164
- if (castShadow || receiveShadow) {
3165
- node.userData.meshData.meshes.forEach((v)=>{
3166
- v.castShadow = castShadow;
3167
- v.receiveShadow = receiveShadow;
3242
+ load(_param) {
3243
+ var _this = this;
3244
+ return _async_to_generator(function*() {
3245
+ var { url, ext, onProgress, castShadow = false, receiveShadow = false } = _param, props = _object_without_properties_loose(_param, [
3246
+ "url",
3247
+ "ext",
3248
+ "onProgress",
3249
+ "castShadow",
3250
+ "receiveShadow"
3251
+ ]);
3252
+ const node = yield _this.loadAsset({
3253
+ url,
3254
+ ext,
3255
+ onProgress
3168
3256
  });
3169
- }
3170
- this.addNode(node, props);
3171
- return node;
3257
+ if (castShadow || receiveShadow) {
3258
+ node.userData.meshData.meshes.forEach((v)=>{
3259
+ v.castShadow = castShadow;
3260
+ v.receiveShadow = receiveShadow;
3261
+ });
3262
+ }
3263
+ _this.addNode(node, props);
3264
+ return node;
3265
+ })();
3172
3266
  }
3173
3267
  tween(target) {
3174
3268
  return this._tweenManager.tween(target);
@@ -3217,9 +3311,20 @@ class Viewer extends EventEmitter {
3217
3311
  removeComponent(node, component) {
3218
3312
  return this._componentManager.removeComponent(node, component);
3219
3313
  }
3220
- addNode(object, { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
3314
+ addNode(object, _param = {}) {
3315
+ var { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene } = _param, props = _object_without_properties_loose(_param, [
3316
+ "args",
3317
+ "debug",
3318
+ "scale",
3319
+ "position",
3320
+ "rotation",
3321
+ "shadowArgs",
3322
+ "makeDefault",
3323
+ "component",
3324
+ "parent"
3325
+ ]);
3221
3326
  let node = null;
3222
- let ins = Viewer._getClassInstance(object, args);
3327
+ let ins = getClassInstance(object, args);
3223
3328
  if (ins.isObject3D) {
3224
3329
  node = ins;
3225
3330
  parent.add(ins);
@@ -3339,12 +3444,30 @@ class Viewer extends EventEmitter {
3339
3444
  Viewer.CompileObject3D(this._renderer, this._scene, this._camera, this._scene);
3340
3445
  }
3341
3446
  }
3342
- constructor({ root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
3343
- fov: 45,
3344
- near: 1,
3345
- far: 1000,
3346
- position: new three.Vector3(0, 0, 4)
3347
- }, targetFrameRate = -1, colorSpace = three.SRGBColorSpace, toneMapping = three.LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", loader = {}, tasker = {}, ...webglOpts } = {}){
3447
+ constructor(_param = {}){
3448
+ var { root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
3449
+ fov: 45,
3450
+ near: 1,
3451
+ far: 1000,
3452
+ position: new three.Vector3(0, 0, 4)
3453
+ }, targetFrameRate = -1, colorSpace = three.SRGBColorSpace, toneMapping = three.LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", loader = {}, tasker = {} } = _param, webglOpts = _object_without_properties_loose(_param, [
3454
+ "root",
3455
+ "canvas",
3456
+ "autoStart",
3457
+ "autoResize",
3458
+ "shadows",
3459
+ "camera",
3460
+ "targetFrameRate",
3461
+ "colorSpace",
3462
+ "toneMapping",
3463
+ "toneMappingExposure",
3464
+ "maxDPR",
3465
+ "path",
3466
+ "resourcePath",
3467
+ "dracoPath",
3468
+ "loader",
3469
+ "tasker"
3470
+ ]);
3348
3471
  super();
3349
3472
  this._dpr = 1;
3350
3473
  this._width = 1;
@@ -3448,6 +3571,7 @@ exports.aGLTFLoader = aGLTFLoader;
3448
3571
  exports.aHDRLoader = aHDRLoader;
3449
3572
  exports.aJSONLoader = aJSONLoader;
3450
3573
  exports.aTextureLoader = aTextureLoader;
3574
+ exports.getClassInstance = getClassInstance;
3451
3575
  exports.mixin = mixin;
3452
3576
  exports.property = property;
3453
3577
  //# sourceMappingURL=main.js.map