@xviewer.js/core 1.0.0-alpha.8 → 1.0.0-beta.1

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 = {
@@ -1157,18 +1161,65 @@ class aTextureLoader extends aLoader {
1157
1161
  }
1158
1162
  }
1159
1163
 
1164
+ /******************************************************************************
1165
+ Copyright (c) Microsoft Corporation.
1166
+
1167
+ Permission to use, copy, modify, and/or distribute this software for any
1168
+ purpose with or without fee is hereby granted.
1169
+
1170
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1171
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1172
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1173
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1174
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1175
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1176
+ PERFORMANCE OF THIS SOFTWARE.
1177
+ ***************************************************************************** */
1178
+ /* global Reflect, Promise, SuppressedError, Symbol */
1179
+
1180
+
1181
+ function __decorate(decorators, target, key, desc) {
1182
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1183
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1184
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1185
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1186
+ }
1187
+
1188
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1189
+ var e = new Error(message);
1190
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1191
+ };
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
+ }
1160
1207
  class PropertyManager {
1161
- static _getProperties(target) {
1162
- return this._propertiesMap.get(target.constructor);
1208
+ static _hasProperties(constructor) {
1209
+ return PropertyManager._propertyMap.has(constructor);
1163
1210
  }
1164
- static _hasProperties(target) {
1165
- return this._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;
1166
1218
  }
1167
- static _getMergedProperties(target) {
1219
+ static _getMergedProperties(constructor) {
1168
1220
  let props = null;
1169
- let constructor = target.constructor;
1170
1221
  while(constructor !== Object.constructor.prototype){
1171
- let values = PropertyManager._propertiesMap.get(constructor);
1222
+ let values = PropertyManager._getProperties(constructor, false);
1172
1223
  if (values) {
1173
1224
  if (props === null) {
1174
1225
  props = Object.create(null);
@@ -1179,17 +1230,29 @@ class PropertyManager {
1179
1230
  }
1180
1231
  return props;
1181
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
+ }
1182
1249
  }
1183
- PropertyManager._propertiesMap = new Map();
1250
+ PropertyManager._classMap = new Map();
1251
+ PropertyManager._propertyMap = new Map();
1184
1252
  function property(target, propertyKey) {
1185
1253
  let options = null;
1186
1254
  function normalized(target, propertyKey) {
1187
- let targetMap = PropertyManager._propertiesMap.get(target.constructor);
1188
- if (targetMap === undefined) {
1189
- targetMap = Object.create(null);
1190
- PropertyManager._propertiesMap.set(target.constructor, targetMap);
1191
- }
1192
- targetMap[propertyKey] = options;
1255
+ PropertyManager._getProperties(target.constructor)[propertyKey] = options;
1193
1256
  }
1194
1257
  if (target === undefined) {
1195
1258
  return property({});
@@ -1202,12 +1265,6 @@ function property(target, propertyKey) {
1202
1265
  }
1203
1266
  }
1204
1267
 
1205
- function _ts_decorate$3(decorators, target, key, desc) {
1206
- var c = arguments.length, r = c < 3 ? target : desc, d;
1207
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1208
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1209
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1210
- }
1211
1268
  const CinestationBlendStyle = {
1212
1269
  Linear: Easing.Linear.None,
1213
1270
  QuadraticIn: Easing.Quadratic.In,
@@ -1220,12 +1277,12 @@ class CinestationBlendDefinition {
1220
1277
  this.time = 4;
1221
1278
  }
1222
1279
  }
1223
- _ts_decorate$3([
1280
+ __decorate([
1224
1281
  property({
1225
1282
  value: CinestationBlendStyle
1226
1283
  })
1227
1284
  ], CinestationBlendDefinition.prototype, "style", void 0);
1228
- _ts_decorate$3([
1285
+ __decorate([
1229
1286
  property
1230
1287
  ], CinestationBlendDefinition.prototype, "time", void 0);
1231
1288
 
@@ -1289,12 +1346,6 @@ class Component extends ObjectInstance {
1289
1346
  }
1290
1347
  }
1291
1348
 
1292
- function _ts_decorate$2(decorators, target, key, desc) {
1293
- var c = arguments.length, r = c < 3 ? target : desc, d;
1294
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1295
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1296
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1297
- }
1298
1349
  const { clamp: clamp$1, lerp } = three.MathUtils;
1299
1350
  class CinestationBrain extends Component {
1300
1351
  get vcam() {
@@ -1367,16 +1418,10 @@ class CinestationBrain extends Component {
1367
1418
  this.onChanged = null;
1368
1419
  }
1369
1420
  }
1370
- _ts_decorate$2([
1421
+ __decorate([
1371
1422
  property
1372
1423
  ], CinestationBrain.prototype, "brainBlend", void 0);
1373
1424
 
1374
- function _ts_decorate$1(decorators, target, key, desc) {
1375
- var c = arguments.length, r = c < 3 ? target : desc, d;
1376
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1377
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1378
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1379
- }
1380
1425
  class VirtualCamera extends Component {
1381
1426
  get finalPosition() {
1382
1427
  return this._finalPosition.copy(this.node.position).add(this.correctPosition);
@@ -1418,17 +1463,17 @@ class VirtualCamera extends Component {
1418
1463
  this.trackedObjectOffset = new three.Vector3();
1419
1464
  }
1420
1465
  }
1421
- _ts_decorate$1([
1466
+ __decorate([
1422
1467
  property({
1423
1468
  dir: "lens"
1424
1469
  })
1425
1470
  ], VirtualCamera.prototype, "fov", void 0);
1426
- _ts_decorate$1([
1471
+ __decorate([
1427
1472
  property({
1428
1473
  dir: "lens"
1429
1474
  })
1430
1475
  ], VirtualCamera.prototype, "near", void 0);
1431
- _ts_decorate$1([
1476
+ __decorate([
1432
1477
  property({
1433
1478
  dir: "lens"
1434
1479
  })
@@ -1964,12 +2009,6 @@ function quarticDamp(current, target, dampTime, deltaTime) {
1964
2009
 
1965
2010
  const Vector3_ZERO = new three.Vector3();
1966
2011
 
1967
- function _ts_decorate(decorators, target, key, desc) {
1968
- var c = arguments.length, r = c < 3 ? target : desc, d;
1969
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1970
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1971
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1972
- }
1973
2012
  const { clamp, degToRad } = three.MathUtils;
1974
2013
  const { abs, tan } = Math;
1975
2014
  const VCamFreeLookMode = {
@@ -2233,37 +2272,37 @@ FreelookVirtualCamera.__xAxis = new three.Vector3();
2233
2272
  FreelookVirtualCamera.__yAxis = new three.Vector3();
2234
2273
  FreelookVirtualCamera.__quat = new three.Quaternion();
2235
2274
  FreelookVirtualCamera.__spherical = new three.Spherical();
2236
- _ts_decorate([
2275
+ __decorate([
2237
2276
  property({
2238
2277
  value: VCamFreeLookMode
2239
2278
  })
2240
2279
  ], FreelookVirtualCamera.prototype, "mode", void 0);
2241
- _ts_decorate([
2280
+ __decorate([
2242
2281
  property({
2243
2282
  dir: "set"
2244
2283
  })
2245
2284
  ], FreelookVirtualCamera.prototype, "forbidX", void 0);
2246
- _ts_decorate([
2285
+ __decorate([
2247
2286
  property({
2248
2287
  dir: "set"
2249
2288
  })
2250
2289
  ], FreelookVirtualCamera.prototype, "forbidY", void 0);
2251
- _ts_decorate([
2290
+ __decorate([
2252
2291
  property({
2253
2292
  dir: "set"
2254
2293
  })
2255
2294
  ], FreelookVirtualCamera.prototype, "forbidZ", void 0);
2256
- _ts_decorate([
2295
+ __decorate([
2257
2296
  property({
2258
2297
  dir: "set"
2259
2298
  })
2260
2299
  ], FreelookVirtualCamera.prototype, "forbidPanX", void 0);
2261
- _ts_decorate([
2300
+ __decorate([
2262
2301
  property({
2263
2302
  dir: "set"
2264
2303
  })
2265
2304
  ], FreelookVirtualCamera.prototype, "forbidPanY", void 0);
2266
- _ts_decorate([
2305
+ __decorate([
2267
2306
  property({
2268
2307
  dir: "set"
2269
2308
  })
@@ -2287,6 +2326,53 @@ class Plane extends three.Mesh {
2287
2326
  }
2288
2327
  }
2289
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
+
2290
2376
  class Caller {
2291
2377
  get pause() {
2292
2378
  return this._pause;
@@ -2791,7 +2877,12 @@ class ResourceManager {
2791
2877
  this._loaders.set(ext, loader);
2792
2878
  }
2793
2879
  }
2794
- 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
+ ]);
2795
2886
  return new Promise((resolve, reject)=>{
2796
2887
  const info = ResourceManager._parseURL(url);
2797
2888
  const texSettings = ResourceManager._splitTextureSettings(props);
@@ -2814,7 +2905,7 @@ class ResourceManager {
2814
2905
  onError: reject
2815
2906
  });
2816
2907
  } else {
2817
- reject("missing loader for " + ext);
2908
+ reject("ResourceManager.loadAsset: missing loader for " + ext);
2818
2909
  }
2819
2910
  }
2820
2911
  });
@@ -2892,7 +2983,7 @@ class PluginManager {
2892
2983
  return ins;
2893
2984
  }
2894
2985
  addPlugin(plugin) {
2895
- const ins = Viewer._getClassInstance(plugin);
2986
+ const ins = getClassInstance(plugin);
2896
2987
  if (this._pluginsMap.has(ins.constructor)) {
2897
2988
  Logger.warn("Plugin already added");
2898
2989
  } else {
@@ -2900,6 +2991,7 @@ class PluginManager {
2900
2991
  ins.install && ins.install();
2901
2992
  this._plugins.push(ins);
2902
2993
  this._pluginsMap.set(ins.constructor, ins);
2994
+ PropertyManager._applyClassProperties(ins.type, ins.constructor);
2903
2995
  }
2904
2996
  return ins;
2905
2997
  }
@@ -2920,9 +3012,6 @@ class PluginManager {
2920
3012
  }
2921
3013
 
2922
3014
  class Viewer extends EventEmitter {
2923
- static _getClassInstance(constructor, args = []) {
2924
- return typeof constructor === "function" ? new constructor(...args) : constructor;
2925
- }
2926
3015
  static _setDirectLightShadow(shadow, props) {
2927
3016
  const shadowCamera = shadow.camera;
2928
3017
  for(let i = 0; i < props.length && i < 6; i++){
@@ -3037,6 +3126,7 @@ class Viewer extends EventEmitter {
3037
3126
  this.addLoader(aGLTFLoader);
3038
3127
  this.addLoader(aHDRLoader);
3039
3128
  this.addLoader(aTextureLoader);
3129
+ this.addLoader(aJSONLoader);
3040
3130
  }
3041
3131
  _frame(time) {
3042
3132
  this._time = time;
@@ -3150,20 +3240,30 @@ class Viewer extends EventEmitter {
3150
3240
  addLoader(Loader) {
3151
3241
  this._resourceManager.addLoader(Loader);
3152
3242
  }
3153
- async load({ url, ext, onProgress, castShadow = false, receiveShadow = false, ...props }) {
3154
- const node = await this.loadAsset({
3155
- url,
3156
- ext,
3157
- onProgress
3158
- });
3159
- if (castShadow || receiveShadow) {
3160
- node.userData.meshData.meshes.forEach((v)=>{
3161
- v.castShadow = castShadow;
3162
- v.receiveShadow = receiveShadow;
3243
+ load(_param) {
3244
+ var _this = this;
3245
+ return _async_to_generator(function*() {
3246
+ var { url, ext, onProgress, castShadow = false, receiveShadow = false } = _param, props = _object_without_properties_loose(_param, [
3247
+ "url",
3248
+ "ext",
3249
+ "onProgress",
3250
+ "castShadow",
3251
+ "receiveShadow"
3252
+ ]);
3253
+ const node = yield _this.loadAsset({
3254
+ url,
3255
+ ext,
3256
+ onProgress
3163
3257
  });
3164
- }
3165
- this.addNode(node, props);
3166
- return node;
3258
+ if (castShadow || receiveShadow) {
3259
+ node.userData.meshData.meshes.forEach((v)=>{
3260
+ v.castShadow = castShadow;
3261
+ v.receiveShadow = receiveShadow;
3262
+ });
3263
+ }
3264
+ _this.addNode(node, props);
3265
+ return node;
3266
+ })();
3167
3267
  }
3168
3268
  tween(target) {
3169
3269
  return this._tweenManager.tween(target);
@@ -3212,9 +3312,20 @@ class Viewer extends EventEmitter {
3212
3312
  removeComponent(node, component) {
3213
3313
  return this._componentManager.removeComponent(node, component);
3214
3314
  }
3215
- addNode(object, { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
3315
+ addNode(object, _param = {}) {
3316
+ var { args, debug, scale, position, rotation, shadowArgs, makeDefault, component, parent = this._scene } = _param, props = _object_without_properties_loose(_param, [
3317
+ "args",
3318
+ "debug",
3319
+ "scale",
3320
+ "position",
3321
+ "rotation",
3322
+ "shadowArgs",
3323
+ "makeDefault",
3324
+ "component",
3325
+ "parent"
3326
+ ]);
3216
3327
  let node = null;
3217
- let ins = Viewer._getClassInstance(object, args);
3328
+ let ins = getClassInstance(object, args);
3218
3329
  if (ins.isObject3D) {
3219
3330
  node = ins;
3220
3331
  parent.add(ins);
@@ -3223,7 +3334,7 @@ class Viewer extends EventEmitter {
3223
3334
  parent.add(node);
3224
3335
  this._componentManager.addComponent(node, ins);
3225
3336
  } else {
3226
- throw Error("unsuport object");
3337
+ throw Error("Viewer.addNode: unsuport object");
3227
3338
  }
3228
3339
  if (component) {
3229
3340
  const components = Array.isArray(component) ? component : [
@@ -3312,7 +3423,7 @@ class Viewer extends EventEmitter {
3312
3423
  if (target.every((v)=>v.isMaterial)) {
3313
3424
  Viewer.CompileMaterial(this._renderer, this._scene, this._camera, target);
3314
3425
  } else {
3315
- throw Error("unsuport material");
3426
+ throw Error("Viewer.compile: unsuport material");
3316
3427
  }
3317
3428
  } else if (typeof target === "object") {
3318
3429
  if (target.isMaterial) {
@@ -3334,12 +3445,30 @@ class Viewer extends EventEmitter {
3334
3445
  Viewer.CompileObject3D(this._renderer, this._scene, this._camera, this._scene);
3335
3446
  }
3336
3447
  }
3337
- constructor({ root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
3338
- fov: 45,
3339
- near: 1,
3340
- far: 1000,
3341
- position: new three.Vector3(0, 0, 4)
3342
- }, 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 } = {}){
3448
+ constructor(_param = {}){
3449
+ var { root, canvas, autoStart = true, autoResize = true, shadows = false, camera = {
3450
+ fov: 45,
3451
+ near: 1,
3452
+ far: 1000,
3453
+ position: new three.Vector3(0, 0, 4)
3454
+ }, 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, [
3455
+ "root",
3456
+ "canvas",
3457
+ "autoStart",
3458
+ "autoResize",
3459
+ "shadows",
3460
+ "camera",
3461
+ "targetFrameRate",
3462
+ "colorSpace",
3463
+ "toneMapping",
3464
+ "toneMappingExposure",
3465
+ "maxDPR",
3466
+ "path",
3467
+ "resourcePath",
3468
+ "dracoPath",
3469
+ "loader",
3470
+ "tasker"
3471
+ ]);
3343
3472
  super();
3344
3473
  this._dpr = 1;
3345
3474
  this._width = 1;
@@ -3443,6 +3572,7 @@ exports.aGLTFLoader = aGLTFLoader;
3443
3572
  exports.aHDRLoader = aHDRLoader;
3444
3573
  exports.aJSONLoader = aJSONLoader;
3445
3574
  exports.aTextureLoader = aTextureLoader;
3575
+ exports.getClassInstance = getClassInstance;
3446
3576
  exports.mixin = mixin;
3447
3577
  exports.property = property;
3448
3578
  //# sourceMappingURL=main.js.map